From df2092f8869c29ecd88a8e4730285488f37f6cc9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 03:44:55 +0000 Subject: [PATCH 001/124] Auto-generated commit aa97ffe353b938cd1f33affbb42852a2989ee2d6 --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 281 ++++++ index.d.ts | 102 ++ index.mjs | 4 + index.mjs.map | 1 + package.json | 37 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 3624 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..8310b6e --- /dev/null +++ b/README.md @@ -0,0 +1,281 @@ + + +# Serialize Meta Data + +[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] + +> Serialize [ndarray][@stdlib/ndarray/ctor] meta data. + + + +
+ +
+ + + + + + + +
+ +## Usage + +```javascript +import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@esm/index.mjs'; +``` + +#### serialize( x ) + +Serializes [ndarray][@stdlib/ndarray/ctor] meta data. + +```javascript +import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; + +var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); +var dv = serialize( arr ); +// returns +``` + +
+ + + + + +
+ +## Notes + +- Serialization is performed according to host byte order (endianness). + +- Meta data format: + + ```text + | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | + ``` + + which translates to the following `ArrayBuffer` layout: + + ```text + ArrayBuffer[ + [int8], + [int16], + [int64], + [ndims*int64], + [ndims*int64], + [int64], + [int8], + [int8], + [int64], + [nsubmodes*int8], + [int32] + ] + ``` + + where `strides` and `offset` are in units of bytes. + +- If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. + +- Buffer length: + + ```text + 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes + ``` + + For example, consider a three-dimensional [ndarray][@stdlib/ndarray/ctor] with one subscript index mode (submode): + + ```text + 33 + (3*16) + 1 = 82 bytes + ``` + +
+ + + + + +
+ +## 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..5ff8a97 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,102 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2021 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; + +/** +* Serializes ndarray meta data. +* +* ## Notes +* +* - Serialization is performed according to host byte order (endianness). +* +* - Meta data format: +* +* ```text +* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | +* ``` +* +* which translates to the following `ArrayBuffer` layout: +* +* ```text +* ArrayBuffer[ +* [int8], +* [int16], +* [int64], +* [ndims*int64], +* [ndims*int64], +* [int64], +* [int8], +* [int8], +* [int64], +* [nsubmodes*int8] +* [int32] +* ] +* ``` +* +* where `strides` and `offset` are in units of bytes. +* +* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. +* +* - Buffer length: +* +* ```text +* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes +* ``` +* +* For example, consider a three-dimensional ndarray with one subscript index mode (submode): +* +* ```text +* 33 + (3*16) + 1 = 82 bytes +* ``` +* +* - Views: +* +* - endianness: `Int8Array( buf, 0, 1 )` +* - dtype: `Int16Array( buf, 1, 1 )` +* - ndims: `Int64Array( buf, 3, 1 )` +* - shape: `Int64Array( buf, 11, ndims )` +* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` +* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` +* - order: `Int8Array( buf, 19+(ndims*16), 1 )` +* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` +* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` +* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` +* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` +* +* @param x - input ndarray +* @returns serialized meta data +* +* @example +* var array = require( `@stdlib/ndarray/array` ); +* +* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); +* +* var dv = serialize( x ); +* // returns +*/ +declare function serialize( x: ndarray ): DataView; + + +// EXPORTS // + +export = serialize; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..92c1fa1 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=e,j=s,h=r,p=n,g=i,_=d.enum,b=m.enum,v=a.enum,u=_(),I=b(),y=v();var c=function(t){var e,s,r,n,i,d,m,a,o,l,_,b,v;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(r=t.dtype,n=t.shape,i=t.strides,_=n.length,a=t.mode||"throw",b=(d=t.submode||[a]).length,e=g(r),o=0,(m=new h(new j(33+16*_+b))).setInt8(o,f?1:0),o+=1,m.setInt16(o,u[r],f),o+=2,m.setBigInt64(o,p(_),f),l=8*_,o+=8,v=0;v<_;v++)m.setBigInt64(o,p(n[v]),f),m.setBigInt64(o+l,p(i[v]*e),f),o+=8;for(o+=l,m.setBigInt64(o,p(t.offset*e),f),o+=8,m.setInt8(o,I[t.order]),o+=1,m.setInt8(o,y[a]),o+=1,m.setBigInt64(o,p(b),f),o+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar serialize = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = serialize;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],"names":["IS_LITTLE_ENDIAN","require$$0","ArrayBuffer","require$$1","DataView","require$$2","BigInt","require$$3","bytesPerElement","require$$4","dtypes","require$$5","enum","orders","require$$6","modes","require$$7","DTYPES","ORDERS","MODES","main","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","setInt8","setInt16","setBigInt64","offset","order","flags","setInt32","float64ToInt64Bytes","assign","Uint8Array","require$$8","serialize","polyfill","bytes","buffer","lib"],"mappings":"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"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..66a802a --- /dev/null +++ b/package.json @@ -0,0 +1,37 @@ +{ + "name": "@stdlib/ndarray-base-serialize-meta-data", + "version": "0.0.0", + "description": "Serialize ndarray meta data.", + "license": "Apache-2.0", + "type": "module", + "main": "./index.mjs", + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/ndarray-base-serialize-meta-data.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "keywords": [ + "stdlib", + "stdtypes", + "types", + "base", + "ndarray", + "serialize", + "serialization", + "protocol", + "meta", + "multidimensional", + "array", + "utilities", + "utility", + "utils", + "util" + ], + "funding": { + "type": "patreon", + "url": "https://www.patreon.com/athan" + } +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f518949 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From 32001912a2bde2945d147a5ff3cf7701da791cb8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 01:04:39 +0000 Subject: [PATCH 002/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 520a089..8907d00 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^0.0.x", "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -100,4 +101,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From e0d990f4f084afbe766c10dacacb87423463d7b6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 06:52:40 +0000 Subject: [PATCH 003/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2796 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 5ff8a97..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 92c1fa1..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=e,j=s,h=r,p=n,g=i,_=d.enum,b=m.enum,v=a.enum,u=_(),I=b(),y=v();var c=function(t){var e,s,r,n,i,d,m,a,o,l,_,b,v;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(r=t.dtype,n=t.shape,i=t.strides,_=n.length,a=t.mode||"throw",b=(d=t.submode||[a]).length,e=g(r),o=0,(m=new h(new j(33+16*_+b))).setInt8(o,f?1:0),o+=1,m.setInt16(o,u[r],f),o+=2,m.setBigInt64(o,p(_),f),l=8*_,o+=8,v=0;v<_;v++)m.setBigInt64(o,p(n[v]),f),m.setBigInt64(o+l,p(i[v]*e),f),o+=8;for(o+=l,m.setBigInt64(o,p(t.offset*e),f),o+=8,m.setInt8(o,I[t.order]),o+=1,m.setInt8(o,y[a]),o+=1,m.setBigInt64(o,p(b),f),o+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar serialize = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = serialize;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],"names":["IS_LITTLE_ENDIAN","require$$0","ArrayBuffer","require$$1","DataView","require$$2","BigInt","require$$3","bytesPerElement","require$$4","dtypes","require$$5","enum","orders","require$$6","modes","require$$7","DTYPES","ORDERS","MODES","main","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","setInt8","setInt16","setBigInt64","offset","order","flags","setInt32","float64ToInt64Bytes","assign","Uint8Array","require$$8","serialize","polyfill","bytes","buffer","lib"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f518949..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From d5621d27366f26be21cbc9667c6cfa13087a34e7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 06:53:23 +0000 Subject: [PATCH 004/124] 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 | 45 +- benchmark/benchmark.js | 166 -- branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 219 -- lib/polyfill.js | 223 -- package.json | 73 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 62 - test/test.main.js | 297 --- test/test.polyfill.js | 297 --- 40 files changed, 2717 insertions(+), 4515 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 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 5d4cb7a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T22:37:50.092Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 ba4c75c..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -222,7 +215,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -282,7 +275,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index f09788a..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/serialize-meta-data" -click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 40e9e3f..5ff8a97 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1bbee2b --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian' ;\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes' ;\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport Uint8Array from '@stdlib/array-uint8' ;\nimport DataView from '@stdlib/array-dataview' ;\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element' ;\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes' ;\nimport { enum as orders } from '@stdlib/ndarray-orders' ;\nimport { enum as modes } from '@stdlib/ndarray-index-modes' ;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support' ;\nimport serialize from './main.js' ;\nimport polyfill from './polyfill.js' ;\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = serialize;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a5e3ff5..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var serialize = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = serialize; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16ed1da..0000000 --- a/lib/main.js +++ /dev/null @@ -1,219 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index aa7ab25..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,223 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( x.offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 8907d00..778649e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-dataview": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/assert-has-bigint-support": "^0.0.x", - "@stdlib/assert-is-little-endian": "^0.0.x", - "@stdlib/bigint-ctor": "^0.0.x", - "@stdlib/ndarray-base-bytes-per-element": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^0.0.x", - "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-dataview": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/number-float64-base-from-int64-bytes": "^0.0.x", - "proxyquire": "^2.0.0", - "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", @@ -96,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..69bd858 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From dca2106d9352b2b75427373224de0d45d22e66e1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 18:15:17 +0000 Subject: [PATCH 005/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 520a089..8907d00 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^0.0.x", "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -100,4 +101,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 089ce61409a068f2a873fae3f85a6ab2a665e4e9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 08:41:57 +0000 Subject: [PATCH 006/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2796 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 5ff8a97..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1bbee2b..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian' ;\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes' ;\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport Uint8Array from '@stdlib/array-uint8' ;\nimport DataView from '@stdlib/array-dataview' ;\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element' ;\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes' ;\nimport { enum as orders } from '@stdlib/ndarray-orders' ;\nimport { enum as modes } from '@stdlib/ndarray-index-modes' ;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support' ;\nimport serialize from './main.js' ;\nimport polyfill from './polyfill.js' ;\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = serialize;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 69bd858..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 2c754739856bebaf9cc15dd79e9915e9852c1f6a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 08:42:55 +0000 Subject: [PATCH 007/124] 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 | 45 +- benchmark/benchmark.js | 166 -- branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 219 -- lib/polyfill.js | 223 -- package.json | 73 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 62 - test/test.main.js | 297 --- test/test.polyfill.js | 297 --- 40 files changed, 2717 insertions(+), 4515 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 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 ae5905c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T01:32:04.753Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 ba4c75c..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -222,7 +215,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -282,7 +275,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index f09788a..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/serialize-meta-data" -click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 40e9e3f..5ff8a97 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1bbee2b --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian' ;\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes' ;\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport Uint8Array from '@stdlib/array-uint8' ;\nimport DataView from '@stdlib/array-dataview' ;\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element' ;\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes' ;\nimport { enum as orders } from '@stdlib/ndarray-orders' ;\nimport { enum as modes } from '@stdlib/ndarray-index-modes' ;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support' ;\nimport serialize from './main.js' ;\nimport polyfill from './polyfill.js' ;\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = serialize;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a5e3ff5..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var serialize = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = serialize; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16ed1da..0000000 --- a/lib/main.js +++ /dev/null @@ -1,219 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index aa7ab25..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,223 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( x.offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 8907d00..778649e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-dataview": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/assert-has-bigint-support": "^0.0.x", - "@stdlib/assert-is-little-endian": "^0.0.x", - "@stdlib/bigint-ctor": "^0.0.x", - "@stdlib/ndarray-base-bytes-per-element": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^0.0.x", - "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-dataview": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/number-float64-base-from-int64-bytes": "^0.0.x", - "proxyquire": "^2.0.0", - "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", @@ -96,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d599aba --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 187fc50cc0757609398ad11173f70cf9fc213414 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:47:57 +0000 Subject: [PATCH 008/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 520a089..8907d00 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^0.0.x", "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -100,4 +101,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 22525febe6ef20440d306117971f87de5f8346e5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 19:03:57 +0000 Subject: [PATCH 009/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2796 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 5ff8a97..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1bbee2b..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian' ;\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes' ;\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport Uint8Array from '@stdlib/array-uint8' ;\nimport DataView from '@stdlib/array-dataview' ;\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element' ;\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes' ;\nimport { enum as orders } from '@stdlib/ndarray-orders' ;\nimport { enum as modes } from '@stdlib/ndarray-index-modes' ;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support' ;\nimport serialize from './main.js' ;\nimport polyfill from './polyfill.js' ;\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = serialize;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d599aba..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From cb9ae44e091278f22b8f83d5a379c27773d6e0c7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 19:04:57 +0000 Subject: [PATCH 010/124] 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 | 45 +- benchmark/benchmark.js | 166 -- branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 219 -- lib/polyfill.js | 223 -- package.json | 73 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 62 - test/test.main.js | 297 --- test/test.polyfill.js | 297 --- 39 files changed, 2717 insertions(+), 4480 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 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 ba4c75c..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -222,7 +215,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -282,7 +275,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index f09788a..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/serialize-meta-data" -click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 40e9e3f..5ff8a97 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1bbee2b --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian' ;\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes' ;\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport Uint8Array from '@stdlib/array-uint8' ;\nimport DataView from '@stdlib/array-dataview' ;\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element' ;\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes' ;\nimport { enum as orders } from '@stdlib/ndarray-orders' ;\nimport { enum as modes } from '@stdlib/ndarray-index-modes' ;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support' ;\nimport serialize from './main.js' ;\nimport polyfill from './polyfill.js' ;\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = serialize;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a5e3ff5..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var serialize = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = serialize; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16ed1da..0000000 --- a/lib/main.js +++ /dev/null @@ -1,219 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index aa7ab25..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,223 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( x.offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 8907d00..778649e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-dataview": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/assert-has-bigint-support": "^0.0.x", - "@stdlib/assert-is-little-endian": "^0.0.x", - "@stdlib/bigint-ctor": "^0.0.x", - "@stdlib/ndarray-base-bytes-per-element": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^0.0.x", - "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-dataview": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/number-float64-base-from-int64-bytes": "^0.0.x", - "proxyquire": "^2.0.0", - "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", @@ -96,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5bbcde5 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 8471f1dc2dd2bb52a8d0306874e1965bd790f0d9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:54:09 +0000 Subject: [PATCH 011/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 520a089..8907d00 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^0.0.x", "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -100,4 +101,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 61ff21df93ddbada6f0d3e2e175aab3093d105cc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 17:57:22 +0000 Subject: [PATCH 012/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2796 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 5ff8a97..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1bbee2b..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian' ;\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes' ;\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport Uint8Array from '@stdlib/array-uint8' ;\nimport DataView from '@stdlib/array-dataview' ;\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element' ;\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes' ;\nimport { enum as orders } from '@stdlib/ndarray-orders' ;\nimport { enum as modes } from '@stdlib/ndarray-index-modes' ;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support' ;\nimport serialize from './main.js' ;\nimport polyfill from './polyfill.js' ;\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = serialize;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5bbcde5..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 194d3a7bd126a9ac290257a73ff97992a89e1d37 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 17:58:20 +0000 Subject: [PATCH 013/124] 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 | 45 +- benchmark/benchmark.js | 166 -- branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 219 -- lib/polyfill.js | 223 -- package.json | 73 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 62 - test/test.main.js | 297 --- test/test.polyfill.js | 297 --- 40 files changed, 2717 insertions(+), 4554 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 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 9c222d0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T01:34:43.275Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 ba4c75c..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -222,7 +215,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -282,7 +275,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index f09788a..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/serialize-meta-data" -click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 40e9e3f..5ff8a97 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1bbee2b --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian' ;\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes' ;\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport Uint8Array from '@stdlib/array-uint8' ;\nimport DataView from '@stdlib/array-dataview' ;\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element' ;\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes' ;\nimport { enum as orders } from '@stdlib/ndarray-orders' ;\nimport { enum as modes } from '@stdlib/ndarray-index-modes' ;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support' ;\nimport serialize from './main.js' ;\nimport polyfill from './polyfill.js' ;\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = serialize;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a5e3ff5..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var serialize = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = serialize; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16ed1da..0000000 --- a/lib/main.js +++ /dev/null @@ -1,219 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index aa7ab25..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,223 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( x.offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 8907d00..778649e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-dataview": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/assert-has-bigint-support": "^0.0.x", - "@stdlib/assert-is-little-endian": "^0.0.x", - "@stdlib/bigint-ctor": "^0.0.x", - "@stdlib/ndarray-base-bytes-per-element": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^0.0.x", - "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-dataview": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/number-float64-base-from-int64-bytes": "^0.0.x", - "proxyquire": "^2.0.0", - "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", @@ -96,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a7fa8ba --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 7d56d358ce826d1abc8d1dbd7cd8fcd2d5983142 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:44:40 +0000 Subject: [PATCH 014/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 520a089..8907d00 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^0.0.x", "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -100,4 +101,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From db691ee5a6810c60e5f6f1f7732727d67121da9a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 11:05:45 +0000 Subject: [PATCH 015/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2796 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 5ff8a97..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1bbee2b..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian' ;\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes' ;\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport Uint8Array from '@stdlib/array-uint8' ;\nimport DataView from '@stdlib/array-dataview' ;\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element' ;\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes' ;\nimport { enum as orders } from '@stdlib/ndarray-orders' ;\nimport { enum as modes } from '@stdlib/ndarray-index-modes' ;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support' ;\nimport serialize from './main.js' ;\nimport polyfill from './polyfill.js' ;\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = serialize;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a7fa8ba..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 31a8ab6e2df2095b8c890c98e98954752341eccf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 11:06:46 +0000 Subject: [PATCH 016/124] 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 | 45 +- benchmark/benchmark.js | 166 -- branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 219 -- lib/polyfill.js | 223 -- package.json | 73 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 62 - test/test.main.js | 297 --- test/test.polyfill.js | 297 --- 40 files changed, 2717 insertions(+), 4570 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 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 36ccd8a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T01:33:56.009Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 ba4c75c..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -222,7 +215,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -282,7 +275,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index f09788a..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/serialize-meta-data" -click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 40e9e3f..5ff8a97 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1bbee2b --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian' ;\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes' ;\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport Uint8Array from '@stdlib/array-uint8' ;\nimport DataView from '@stdlib/array-dataview' ;\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element' ;\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes' ;\nimport { enum as orders } from '@stdlib/ndarray-orders' ;\nimport { enum as modes } from '@stdlib/ndarray-index-modes' ;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support' ;\nimport serialize from './main.js' ;\nimport polyfill from './polyfill.js' ;\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = serialize;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a5e3ff5..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var serialize = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = serialize; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16ed1da..0000000 --- a/lib/main.js +++ /dev/null @@ -1,219 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index aa7ab25..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,223 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( x.offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 8907d00..778649e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-dataview": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/assert-has-bigint-support": "^0.0.x", - "@stdlib/assert-is-little-endian": "^0.0.x", - "@stdlib/bigint-ctor": "^0.0.x", - "@stdlib/ndarray-base-bytes-per-element": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^0.0.x", - "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-dataview": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/number-float64-base-from-int64-bytes": "^0.0.x", - "proxyquire": "^2.0.0", - "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", @@ -96,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1aa0d37 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 78e00c9fe633b6f62c252f42b92a116a9c1c6752 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 04:11:48 +0000 Subject: [PATCH 017/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 520a089..8907d00 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^0.0.x", "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -100,4 +101,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From f063874457e98c422d7c78d6bee641d43d7e5d9f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 15:42:47 +0000 Subject: [PATCH 018/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2796 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 5ff8a97..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1bbee2b..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian' ;\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes' ;\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport Uint8Array from '@stdlib/array-uint8' ;\nimport DataView from '@stdlib/array-dataview' ;\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element' ;\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes' ;\nimport { enum as orders } from '@stdlib/ndarray-orders' ;\nimport { enum as modes } from '@stdlib/ndarray-index-modes' ;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support' ;\nimport serialize from './main.js' ;\nimport polyfill from './polyfill.js' ;\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = serialize;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1aa0d37..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 2879b2b7419f64aaff4f8791081fb2e82382589a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 15:43:32 +0000 Subject: [PATCH 019/124] 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 | 45 +- benchmark/benchmark.js | 166 -- branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 219 -- lib/polyfill.js | 223 -- package.json | 73 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 62 - test/test.main.js | 297 --- test/test.polyfill.js | 297 --- 40 files changed, 2717 insertions(+), 4570 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 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 3d18b35..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T02:00:58.313Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 ba4c75c..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -222,7 +215,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -282,7 +275,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index f09788a..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/serialize-meta-data" -click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 40e9e3f..5ff8a97 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1bbee2b --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian' ;\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes' ;\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport Uint8Array from '@stdlib/array-uint8' ;\nimport DataView from '@stdlib/array-dataview' ;\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element' ;\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes' ;\nimport { enum as orders } from '@stdlib/ndarray-orders' ;\nimport { enum as modes } from '@stdlib/ndarray-index-modes' ;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support' ;\nimport builtin from './main.js' ;\nimport polyfill from './polyfill.js' ;\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16ed1da..0000000 --- a/lib/main.js +++ /dev/null @@ -1,219 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index aa7ab25..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,223 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( x.offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 8907d00..778649e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-dataview": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/assert-has-bigint-support": "^0.0.x", - "@stdlib/assert-is-little-endian": "^0.0.x", - "@stdlib/bigint-ctor": "^0.0.x", - "@stdlib/ndarray-base-bytes-per-element": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^0.0.x", - "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-dataview": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/number-float64-base-from-int64-bytes": "^0.0.x", - "proxyquire": "^2.0.0", - "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", @@ -96,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..134b0c4 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From be84e398b0f28a47700bc772785abb74d433598e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 03:57:19 +0000 Subject: [PATCH 020/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 520a089..8907d00 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^0.0.x", "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -100,4 +101,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 55bb3c875c10600a0133b3896ffa67d31eb1cceb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 11:56:51 +0000 Subject: [PATCH 021/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2796 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 5ff8a97..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1bbee2b..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian' ;\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes' ;\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport Uint8Array from '@stdlib/array-uint8' ;\nimport DataView from '@stdlib/array-dataview' ;\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element' ;\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes' ;\nimport { enum as orders } from '@stdlib/ndarray-orders' ;\nimport { enum as modes } from '@stdlib/ndarray-index-modes' ;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support' ;\nimport builtin from './main.js' ;\nimport polyfill from './polyfill.js' ;\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 134b0c4..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 1abbf867f0bf72acef06ebfdb6e38d78be027630 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 11:57:42 +0000 Subject: [PATCH 022/124] 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 | 45 +- benchmark/benchmark.js | 166 - branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 219 -- lib/polyfill.js | 223 -- package.json | 73 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 62 - test/test.main.js | 297 -- test/test.polyfill.js | 297 -- 40 files changed, 4072 insertions(+), 4570 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 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 6444671..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T01:47:13.774Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 ba4c75c..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ea53760..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -222,7 +215,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -282,7 +275,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index f09788a..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/serialize-meta-data" -click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 40e9e3f..5ff8a97 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1bbee2b --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian' ;\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes' ;\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport Uint8Array from '@stdlib/array-uint8' ;\nimport DataView from '@stdlib/array-dataview' ;\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element' ;\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes' ;\nimport { enum as orders } from '@stdlib/ndarray-orders' ;\nimport { enum as modes } from '@stdlib/ndarray-index-modes' ;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support' ;\nimport builtin from './main.js' ;\nimport polyfill from './polyfill.js' ;\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16ed1da..0000000 --- a/lib/main.js +++ /dev/null @@ -1,219 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index aa7ab25..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,223 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( x.offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 8907d00..778649e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-dataview": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/assert-has-bigint-support": "^0.0.x", - "@stdlib/assert-is-little-endian": "^0.0.x", - "@stdlib/bigint-ctor": "^0.0.x", - "@stdlib/ndarray-base-bytes-per-element": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^0.0.x", - "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-dataview": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/number-float64-base-from-int64-bytes": "^0.0.x", - "proxyquire": "^2.0.0", - "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", @@ -96,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0c4d747 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 386d7a07d206701ffcfbee9b20cc149515b6bae1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 3 Nov 2022 22:41:31 +0000 Subject: [PATCH 023/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 520a089..8907d00 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^0.0.x", "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -100,4 +101,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 76dd8f0eaa83805dbd7d7c4e7e70f5dd9b231758 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 11:23:40 +0000 Subject: [PATCH 024/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4151 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 5ff8a97..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1bbee2b..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian' ;\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes' ;\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport Uint8Array from '@stdlib/array-uint8' ;\nimport DataView from '@stdlib/array-dataview' ;\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element' ;\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes' ;\nimport { enum as orders } from '@stdlib/ndarray-orders' ;\nimport { enum as modes } from '@stdlib/ndarray-index-modes' ;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support' ;\nimport builtin from './main.js' ;\nimport polyfill from './polyfill.js' ;\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0c4d747..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 49f8da8ff0282191b2dfb1e7e6c2244bf6dc335f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 11:24:33 +0000 Subject: [PATCH 025/124] 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 | 45 +- benchmark/benchmark.js | 166 - branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 219 -- lib/polyfill.js | 223 -- package.json | 73 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 62 - test/test.main.js | 297 -- test/test.polyfill.js | 297 -- 40 files changed, 4072 insertions(+), 4591 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 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 df7930e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T22:40:56.182Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 ba4c75c..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ea53760..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -222,7 +215,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -282,7 +275,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index f09788a..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/serialize-meta-data" -click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 40e9e3f..5ff8a97 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1bbee2b --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian' ;\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes' ;\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport Uint8Array from '@stdlib/array-uint8' ;\nimport DataView from '@stdlib/array-dataview' ;\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element' ;\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes' ;\nimport { enum as orders } from '@stdlib/ndarray-orders' ;\nimport { enum as modes } from '@stdlib/ndarray-index-modes' ;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support' ;\nimport builtin from './main.js' ;\nimport polyfill from './polyfill.js' ;\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":";;69BAkCA,IAAIA,EAASC,IACTC,EAASC,IACTC,EAAQC,ICDZ,IAAIL,EAASC,IACTC,EAASC,IACTC,EAAQC,ICiBZ,IAAAC,EATKC,IF8EL,SAAoBC,GACnB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKb,EAAEc,wBACN,OAAOd,EAAEc,0BAqCV,IAlCAX,EAAKH,EAAEe,MACPX,EAAKJ,EAAEgB,MACPX,EAAKL,EAAEiB,QACPN,EAAIP,EAAGc,OAGPV,EAAIR,EAAEmB,MAAQ,QAEdP,GADAN,EAAKN,EAAEoB,SAAW,CAAEZ,IACbU,OAGPjB,EAASoB,EAAiBlB,GAS1BM,EAAI,GAHJF,EAAI,IAAIe,EAAU,IAAIC,EAHhB,GAAQ,GAAFZ,EAAQC,KAOlBY,QAASf,EAAG,EAAuB,EAAI,GAGzCA,GAAK,EACLF,EAAEkB,SAAUhB,EAAGjB,EAAQW,GAAMuB,GAG7BjB,GAAK,EACLF,EAAEoB,YAAalB,EAAGmB,EAAQjB,GAAKe,GAG/BhB,EAAQ,EAAJC,EACJF,GAAK,EACCI,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAEoB,YAAalB,EAAGmB,EAAQxB,EAAGS,IAAMa,GACnCnB,EAAEoB,YAAalB,EAAEC,EAAGkB,EAAQvB,EAAGQ,GAAGZ,GAAUyB,GAC5CjB,GAAK,EAoBN,IAjBAA,GAAKC,EACLH,EAAEoB,YAAalB,EAAGmB,EAAQ5B,EAAE6B,OAAO5B,GAAUyB,GAG7CjB,GAAK,EACLF,EAAEiB,QAASf,EAAGf,EAAQM,EAAE8B,QAGxBrB,GAAK,EACLF,EAAEiB,QAASf,EAAGb,EAAOY,IAGrBC,GAAK,EACLF,EAAEoB,YAAalB,EAAGmB,EAAQhB,GAAKc,GAG/BjB,GAAK,EACCI,EAAI,EAAGA,EAAID,EAAGC,IACnBN,EAAEiB,QAASf,EAAGb,EAAOU,EAAGO,KACxBJ,GAAK,EASN,OANAP,EAAO,EACFF,EAAE+B,QACN7B,GAAUF,EAAE+B,MAAmB,SAAA,EAAI,GAEpCxB,EAAEyB,SAAUvB,EAAGP,EAAMwB,GAEdnB,CACR,ECxFA,SAAoBP,GACnB,IAAIC,EACAgC,EACA/B,EAEAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKb,EAAEc,wBACN,OAAOd,EAAEc,0BAsCV,IAnCAX,EAAKH,EAAEe,MACPX,EAAKJ,EAAEgB,MACPX,EAAKL,EAAEiB,QACPN,EAAIP,EAAGc,OAGPV,EAAIR,EAAEmB,MAAQ,QAEdP,GADAN,EAAKN,EAAEoB,SAAW,CAAEZ,IACbU,OAGPjB,EAASoB,EAAiBlB,GAM1BI,EAAI,IAAIe,EAAU,IAAIC,EAHhB,GAAQ,GAAFZ,EAAQC,IAIpBqB,EAAQ,IAAIC,EAAY3B,EAAE4B,QAG1B1B,EAAI,EACJF,EAAEiB,QAASf,EAAG,EAAuB,EAAI,GAGzCA,GAAK,EACLF,EAAEkB,SAAUhB,EAAGjB,EAAQW,GAAMuB,GAI7BU,EAAqBzB,EAAGsB,EAAO,EAD/BxB,GAAK,GAILC,EAAQ,EAAJC,EACJF,GAAK,EACCI,EAAI,EAAGA,EAAIF,EAAGE,IACnBuB,EAAqBhC,EAAGS,GAAIoB,EAAO,EAAGxB,GACtC2B,EAAqB/B,EAAGQ,GAAGZ,EAAQgC,EAAO,EAAGxB,EAAEC,GAC/CD,GAAK,EAoBN,IAjBAA,GAAKC,EACL0B,EAAqBpC,EAAE6B,OAAO5B,EAAQgC,EAAO,EAAGxB,GAGhDA,GAAK,EACLF,EAAEiB,QAASf,EAAGf,EAAQM,EAAE8B,QAGxBrB,GAAK,EACLF,EAAEiB,QAASf,EAAGb,EAAOY,IAIrB4B,EAAqBxB,EAAGqB,EAAO,EAD/BxB,GAAK,GAILA,GAAK,EACCI,EAAI,EAAGA,EAAID,EAAGC,IACnBN,EAAEiB,QAASf,EAAGb,EAAOU,EAAGO,KACxBJ,GAAK,EASN,OANAP,EAAO,EACFF,EAAE+B,QACN7B,GAAUF,EAAE+B,MAAmB,SAAA,EAAI,GAEpCxB,EAAEyB,SAAUvB,EAAGP,EAAMwB,GAEdnB,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16ed1da..0000000 --- a/lib/main.js +++ /dev/null @@ -1,219 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index aa7ab25..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,223 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( x.offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 8907d00..778649e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-dataview": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/assert-has-bigint-support": "^0.0.x", - "@stdlib/assert-is-little-endian": "^0.0.x", - "@stdlib/bigint-ctor": "^0.0.x", - "@stdlib/ndarray-base-bytes-per-element": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^0.0.x", - "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-dataview": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/number-float64-base-from-int64-bytes": "^0.0.x", - "proxyquire": "^2.0.0", - "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", @@ -96,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..03b4020 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 8643f46b9123afd3fa02224f6ce46e42361f67da Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 02:30:55 +0000 Subject: [PATCH 026/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a249311..2c34fd7 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^0.0.x", "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -100,4 +101,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From c76fa324e6f191c8ba2ddf8ad0a0aadf3c705cb1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 18:24:30 +0000 Subject: [PATCH 027/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4151 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 5ff8a97..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1bbee2b..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian' ;\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes' ;\nimport ArrayBuffer from '@stdlib/array-buffer' ;\nimport Uint8Array from '@stdlib/array-uint8' ;\nimport DataView from '@stdlib/array-dataview' ;\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element' ;\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes' ;\nimport { enum as orders } from '@stdlib/ndarray-orders' ;\nimport { enum as modes } from '@stdlib/ndarray-index-modes' ;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support' ;\nimport builtin from './main.js' ;\nimport polyfill from './polyfill.js' ;\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 03b4020..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 2c426a3189fd93d37a8ae84abf304275f73a8f9a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 18:25:27 +0000 Subject: [PATCH 028/124] 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 | 45 +- benchmark/benchmark.js | 166 - branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 219 -- lib/polyfill.js | 223 -- package.json | 73 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 62 - test/test.main.js | 297 -- test/test.polyfill.js | 297 -- 40 files changed, 4072 insertions(+), 4596 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 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 3380d65..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T02:30:14.839Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 ba4c75c..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ea53760..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -222,7 +215,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -282,7 +275,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index f09788a..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/serialize-meta-data" -click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 40e9e3f..5ff8a97 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1bbee2b --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16ed1da..0000000 --- a/lib/main.js +++ /dev/null @@ -1,219 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index aa7ab25..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,223 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( x.offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 2c34fd7..778649e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-dataview": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/assert-has-bigint-support": "^0.0.x", - "@stdlib/assert-is-little-endian": "^0.0.x", - "@stdlib/bigint-ctor": "^0.0.x", - "@stdlib/ndarray-base-bytes-per-element": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^0.0.x", - "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-dataview": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/number-float64-base-from-int64-bytes": "^0.0.x", - "proxyquire": "^2.0.0", - "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", @@ -96,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b826b50 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 40388a5f47bcf7362e7c64aa18beae3fad58e047 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 03:11:18 +0000 Subject: [PATCH 029/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 89fd68a..454067a 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^0.0.x", "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -100,4 +101,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 3776641fe1561286420f41d13860122e7a47bc73 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 10:38:08 +0000 Subject: [PATCH 030/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4151 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 5ff8a97..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1bbee2b..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b826b50..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 7ceaff9c1c3d10ba2e76fa750dc374dfd0ca13f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 10:39:10 +0000 Subject: [PATCH 031/124] 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 | 45 +- benchmark/benchmark.js | 166 - branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 219 -- lib/polyfill.js | 223 -- package.json | 73 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 62 - test/test.main.js | 297 -- test/test.polyfill.js | 297 -- 40 files changed, 4072 insertions(+), 4607 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 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 6ba1262..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-01-01T01:39:17.937Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 ba4c75c..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ea53760..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -222,7 +215,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -282,7 +275,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index f09788a..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/serialize-meta-data" -click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 40e9e3f..5ff8a97 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..382bd22 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16ed1da..0000000 --- a/lib/main.js +++ /dev/null @@ -1,219 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index aa7ab25..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,223 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( x.offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 454067a..778649e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-dataview": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/assert-has-bigint-support": "^0.0.x", - "@stdlib/assert-is-little-endian": "^0.0.x", - "@stdlib/bigint-ctor": "^0.0.x", - "@stdlib/ndarray-base-bytes-per-element": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^0.0.x", - "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-dataview": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/number-float64-base-from-int64-bytes": "^0.0.x", - "proxyquire": "^2.0.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", @@ -96,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..626bb11 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From b0eb8e16f7f0ed766f486243fa75262329b33760 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 04:08:37 +0000 Subject: [PATCH 032/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 89fd68a..454067a 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "@stdlib/ndarray-index-modes": "^0.0.x", "@stdlib/ndarray-orders": "^0.0.x", "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -100,4 +101,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 32d0def52add23e6bb62379c777486380bbae2ef Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 15:44:17 +0000 Subject: [PATCH 033/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4151 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 5ff8a97..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 382bd22..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 626bb11..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 44e74ab5efa052db174c3c8a1fc759be4aa57d14 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 15:45:12 +0000 Subject: [PATCH 034/124] 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 | 45 +- benchmark/benchmark.js | 166 - branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 219 - lib/polyfill.js | 223 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 62 - test/test.main.js | 297 - test/test.polyfill.js | 297 - 40 files changed, 6205 insertions(+), 4607 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 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 e504d90..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T02:14:47.013Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 ba4c75c..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ea53760..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -222,7 +215,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -282,7 +275,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index f09788a..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/serialize-meta-data" -click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 40e9e3f..5ff8a97 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..382bd22 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16ed1da..0000000 --- a/lib/main.js +++ /dev/null @@ -1,219 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index aa7ab25..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,223 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( x.offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 454067a..778649e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-dataview": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/assert-has-bigint-support": "^0.0.x", - "@stdlib/assert-is-little-endian": "^0.0.x", - "@stdlib/bigint-ctor": "^0.0.x", - "@stdlib/ndarray-base-bytes-per-element": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/ndarray-orders": "^0.0.x", - "@stdlib/number-float64-base-to-int64-bytes": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-dataview": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/number-float64-base-from-int64-bytes": "^0.0.x", - "proxyquire": "^2.0.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", @@ -96,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..bd97d4f --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 54aeb545affd9fae86cb9f5811af741e8c72aeb2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 10:12:56 +0000 Subject: [PATCH 035/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3362db9..a1baac3 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "@stdlib/ndarray-index-modes": "^0.0.8", "@stdlib/ndarray-orders": "^0.0.8", "@stdlib/number-float64-base-to-int64-bytes": "^0.0.6", - "@stdlib/types": "^0.0.14" + "@stdlib/types": "^0.0.14", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/array-float64": "^0.0.6", @@ -100,4 +101,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 3eeb9932a2883314612cfa62eaa9f34ecc241195 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 19:22:48 +0000 Subject: [PATCH 036/124] Remove files --- index.d.ts | 102 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6284 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 5ff8a97..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 382bd22..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bd97d4f..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e7b01cba7c390eac3162a207d76455a748e3dd48 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 19:23:45 +0000 Subject: [PATCH 037/124] 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 | 45 +- benchmark/benchmark.js | 166 - branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 219 - lib/polyfill.js | 223 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 62 - test/test.main.js | 297 - test/test.polyfill.js | 297 - 40 files changed, 6205 insertions(+), 4742 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 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 71ed5dc..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-03-01T06:30:20.181Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 ba4c75c..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ea53760..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -222,7 +215,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -282,7 +275,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e8174da..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 40e9e3f..5ff8a97 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..382bd22 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16ed1da..0000000 --- a/lib/main.js +++ /dev/null @@ -1,219 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index aa7ab25..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,223 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( x.offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index a1baac3..14df722 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.6", - "@stdlib/array-dataview": "^0.0.6", - "@stdlib/array-uint8": "^0.0.7", - "@stdlib/assert-has-bigint-support": "^0.0.8", - "@stdlib/assert-is-little-endian": "^0.0.7", - "@stdlib/bigint-ctor": "^0.0.7", - "@stdlib/ndarray-base-bytes-per-element": "^0.0.8", - "@stdlib/ndarray-dtypes": "^0.0.9", - "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/ndarray-orders": "^0.0.8", - "@stdlib/number-float64-base-to-int64-bytes": "^0.0.6", - "@stdlib/types": "^0.0.14", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-is-dataview": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "@stdlib/ndarray-array": "^0.0.9", - "@stdlib/ndarray-base-ctor": "^0.0.6", - "@stdlib/ndarray-ctor": "^0.0.10", - "@stdlib/number-float64-base-from-int64-bytes": "^0.0.6", - "proxyquire": "^2.0.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", @@ -96,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..aac90b6 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 2a4ce8a9c5babd328abbd29ff03b202dcc4c721b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 09:50:04 +0000 Subject: [PATCH 038/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3362db9..a1baac3 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "@stdlib/ndarray-index-modes": "^0.0.8", "@stdlib/ndarray-orders": "^0.0.8", "@stdlib/number-float64-base-to-int64-bytes": "^0.0.6", - "@stdlib/types": "^0.0.14" + "@stdlib/types": "^0.0.14", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/array-float64": "^0.0.6", @@ -100,4 +101,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 37cde9a5213a5f9bc1c716265237f01dbb74f0da Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 18:08:59 +0000 Subject: [PATCH 039/124] Remove files --- index.d.ts | 102 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6284 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 5ff8a97..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 382bd22..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index aac90b6..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1f23608a358ebc398fbc90b3fcb08286ff0fb453 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 18:09:51 +0000 Subject: [PATCH 040/124] 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 | 45 +- benchmark/benchmark.js | 166 - branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 219 - lib/polyfill.js | 223 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 62 - test/test.main.js | 297 - test/test.polyfill.js | 297 - 40 files changed, 6205 insertions(+), 4748 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 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 e36dc85..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-06-01T06:27:35.025Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 ba4c75c..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ea53760..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -222,7 +215,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -282,7 +275,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e8174da..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 40e9e3f..5ff8a97 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..382bd22 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16ed1da..0000000 --- a/lib/main.js +++ /dev/null @@ -1,219 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index aa7ab25..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,223 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( x.offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index a1baac3..14df722 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.6", - "@stdlib/array-dataview": "^0.0.6", - "@stdlib/array-uint8": "^0.0.7", - "@stdlib/assert-has-bigint-support": "^0.0.8", - "@stdlib/assert-is-little-endian": "^0.0.7", - "@stdlib/bigint-ctor": "^0.0.7", - "@stdlib/ndarray-base-bytes-per-element": "^0.0.8", - "@stdlib/ndarray-dtypes": "^0.0.9", - "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/ndarray-orders": "^0.0.8", - "@stdlib/number-float64-base-to-int64-bytes": "^0.0.6", - "@stdlib/types": "^0.0.14", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-is-dataview": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "@stdlib/ndarray-array": "^0.0.9", - "@stdlib/ndarray-base-ctor": "^0.0.6", - "@stdlib/ndarray-ctor": "^0.0.10", - "@stdlib/number-float64-base-from-int64-bytes": "^0.0.6", - "proxyquire": "^2.0.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", @@ -96,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ef81df1 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 101b36df92f94f6a248cc5b8399e4d549d99a818 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 09:14:45 +0000 Subject: [PATCH 041/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3362db9..a1baac3 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "@stdlib/ndarray-index-modes": "^0.0.8", "@stdlib/ndarray-orders": "^0.0.8", "@stdlib/number-float64-base-to-int64-bytes": "^0.0.6", - "@stdlib/types": "^0.0.14" + "@stdlib/types": "^0.0.14", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/array-float64": "^0.0.6", @@ -100,4 +101,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 230d921112a69a373d8503c31a464dd9b4c41a46 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 18:26:53 +0000 Subject: [PATCH 042/124] Remove files --- index.d.ts | 102 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6284 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 5ff8a97..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 382bd22..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":";;69BAkCA,IAAIA,EAASC,IACTC,EAASC,IACTC,EAAQC,ICDZ,IAAIL,EAASC,IACTC,EAASC,IACTC,EAAQC,ICiBZ,IAAAC,EATKC,IF8EL,SAAoBC,GACnB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKb,EAAEc,wBACN,OAAOd,EAAEc,0BAqCV,IAlCAX,EAAKH,EAAEe,MACPX,EAAKJ,EAAEgB,MACPX,EAAKL,EAAEiB,QACPN,EAAIP,EAAGc,OAGPV,EAAIR,EAAEmB,MAAQ,QAEdP,GADAN,EAAKN,EAAEoB,SAAW,CAAEZ,IACbU,OAGPjB,EAASoB,EAAiBlB,GAS1BM,EAAI,GAHJF,EAAI,IAAIe,EAAU,IAAIC,EAHhB,GAAQ,GAAFZ,EAAQC,KAOlBY,QAASf,EAAG,EAAuB,EAAI,GAGzCA,GAAK,EACLF,EAAEkB,SAAUhB,EAAGjB,EAAQW,GAAMuB,GAG7BjB,GAAK,EACLF,EAAEoB,YAAalB,EAAGmB,EAAQjB,GAAKe,GAG/BhB,EAAQ,EAAJC,EACJF,GAAK,EACCI,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAEoB,YAAalB,EAAGmB,EAAQxB,EAAGS,IAAMa,GACnCnB,EAAEoB,YAAalB,EAAEC,EAAGkB,EAAQvB,EAAGQ,GAAGZ,GAAUyB,GAC5CjB,GAAK,EAoBN,IAjBAA,GAAKC,EACLH,EAAEoB,YAAalB,EAAGmB,EAAQ5B,EAAE6B,OAAO5B,GAAUyB,GAG7CjB,GAAK,EACLF,EAAEiB,QAASf,EAAGf,EAAQM,EAAE8B,QAGxBrB,GAAK,EACLF,EAAEiB,QAASf,EAAGb,EAAOY,IAGrBC,GAAK,EACLF,EAAEoB,YAAalB,EAAGmB,EAAQhB,GAAKc,GAG/BjB,GAAK,EACCI,EAAI,EAAGA,EAAID,EAAGC,IACnBN,EAAEiB,QAASf,EAAGb,EAAOU,EAAGO,KACxBJ,GAAK,EASN,OANAP,EAAO,EACFF,EAAE+B,QACN7B,GAAUF,EAAE+B,MAAmB,SAAA,EAAI,GAEpCxB,EAAEyB,SAAUvB,EAAGP,EAAMwB,GAEdnB,CACR,ECxFA,SAAoBP,GACnB,IAAIC,EACAgC,EACA/B,EAEAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKb,EAAEc,wBACN,OAAOd,EAAEc,0BAsCV,IAnCAX,EAAKH,EAAEe,MACPX,EAAKJ,EAAEgB,MACPX,EAAKL,EAAEiB,QACPN,EAAIP,EAAGc,OAGPV,EAAIR,EAAEmB,MAAQ,QAEdP,GADAN,EAAKN,EAAEoB,SAAW,CAAEZ,IACbU,OAGPjB,EAASoB,EAAiBlB,GAM1BI,EAAI,IAAIe,EAAU,IAAIC,EAHhB,GAAQ,GAAFZ,EAAQC,IAIpBqB,EAAQ,IAAIC,EAAY3B,EAAE4B,QAG1B1B,EAAI,EACJF,EAAEiB,QAASf,EAAG,EAAuB,EAAI,GAGzCA,GAAK,EACLF,EAAEkB,SAAUhB,EAAGjB,EAAQW,GAAMuB,GAI7BU,EAAqBzB,EAAGsB,EAAO,EAD/BxB,GAAK,GAILC,EAAQ,EAAJC,EACJF,GAAK,EACCI,EAAI,EAAGA,EAAIF,EAAGE,IACnBuB,EAAqBhC,EAAGS,GAAIoB,EAAO,EAAGxB,GACtC2B,EAAqB/B,EAAGQ,GAAGZ,EAAQgC,EAAO,EAAGxB,EAAEC,GAC/CD,GAAK,EAoBN,IAjBAA,GAAKC,EACL0B,EAAqBpC,EAAE6B,OAAO5B,EAAQgC,EAAO,EAAGxB,GAGhDA,GAAK,EACLF,EAAEiB,QAASf,EAAGf,EAAQM,EAAE8B,QAGxBrB,GAAK,EACLF,EAAEiB,QAASf,EAAGb,EAAOY,IAIrB4B,EAAqBxB,EAAGqB,EAAO,EAD/BxB,GAAK,GAILA,GAAK,EACCI,EAAI,EAAGA,EAAID,EAAGC,IACnBN,EAAEiB,QAASf,EAAGb,EAAOU,EAAGO,KACxBJ,GAAK,EASN,OANAP,EAAO,EACFF,EAAE+B,QACN7B,GAAUF,EAAE+B,MAAmB,SAAA,EAAI,GAEpCxB,EAAEyB,SAAUvB,EAAGP,EAAMwB,GAEdnB,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ef81df1..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 86c82e2ce8fcb333eba84444c92506881e95f0c7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 18:27:52 +0000 Subject: [PATCH 043/124] 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 | 45 +- benchmark/benchmark.js | 166 - branches.md | 53 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 219 - lib/polyfill.js | 223 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 62 - test/test.main.js | 297 - test/test.polyfill.js | 297 - 40 files changed, 6205 insertions(+), 4748 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 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 74acfe0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-07-01T06:18:32.243Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 ba4c75c..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ea53760..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -222,7 +215,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -282,7 +275,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e8174da..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 40e9e3f..5ff8a97 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..382bd22 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16ed1da..0000000 --- a/lib/main.js +++ /dev/null @@ -1,219 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index aa7ab25..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,223 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( x.offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index a1baac3..14df722 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.0.6", - "@stdlib/array-dataview": "^0.0.6", - "@stdlib/array-uint8": "^0.0.7", - "@stdlib/assert-has-bigint-support": "^0.0.8", - "@stdlib/assert-is-little-endian": "^0.0.7", - "@stdlib/bigint-ctor": "^0.0.7", - "@stdlib/ndarray-base-bytes-per-element": "^0.0.8", - "@stdlib/ndarray-dtypes": "^0.0.9", - "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/ndarray-orders": "^0.0.8", - "@stdlib/number-float64-base-to-int64-bytes": "^0.0.6", - "@stdlib/types": "^0.0.14", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-is-dataview": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "@stdlib/ndarray-array": "^0.0.9", - "@stdlib/ndarray-base-ctor": "^0.0.6", - "@stdlib/ndarray-ctor": "^0.0.10", - "@stdlib/number-float64-base-from-int64-bytes": "^0.0.6", - "proxyquire": "^2.0.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", @@ -96,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..095be9c --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From e132585fc95a87c50225c8bd64da530f02b0c2b2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 06:15:18 +0000 Subject: [PATCH 044/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 89010eb..a6620b4 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "@stdlib/ndarray-index-modes": "^0.1.0", "@stdlib/ndarray-orders": "^0.1.0", "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.1.0" + "@stdlib/types": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0" }, "devDependencies": { "@stdlib/array-float64": "^0.1.0", @@ -100,4 +101,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From ea5a2f3b62a0f11c26ddbed690d063da0d70be55 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 08:30:27 +0000 Subject: [PATCH 045/124] Remove files --- index.d.ts | 102 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6284 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 5ff8a97..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 382bd22..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),g=a(),_=m();var b=t()?function(t){var d,a,m,o,l,p,g,_,b,v,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,_=t.mode||"throw",I=(p=t.submode||[_]).length,d=i(m),b=0,(g=new r(new s(33+16*u+I))).setInt8(b,e?1:0),b+=1,g.setInt16(b,f[m],e),b+=2,g.setBigInt64(b,n(u),e),v=8*u,b+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 095be9c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From bdb3bbb84ae1ed9b1ecb492e7a31577b62aedb63 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 08:31:30 +0000 Subject: [PATCH 046/124] 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 | 45 +- benchmark/benchmark.js | 166 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 219 - lib/polyfill.js | 223 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 62 - test/test.main.js | 297 - test/test.polyfill.js | 297 - 43 files changed, 6205 insertions(+), 4784 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 ba4c75c..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ea53760..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -233,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -293,7 +286,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e8174da..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 68ca4eb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var B=p(function(Z,h){ -var _=require('@stdlib/assert-is-little-endian/dist'),A=require('@stdlib/array-buffer/dist'),T=require('@stdlib/array-dataview/dist'),g=require('@stdlib/bigint-ctor/dist'),L=require('@stdlib/ndarray-base-bytes-per-element/dist'),O=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=O(),P=R(),D=c();function Y(a){var i,n,m,d,I,l,q,t,v,r,e,f,u,s;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(d=a.dtype,I=a.shape,l=a.strides,f=I.length,v=a.mode||"throw",q=a.submode||[v],u=q.length,i=L(d),m=33+f*16+u,t=new T(new A(m)),r=0,t.setInt8(r,_?1:0),r+=1,t.setInt16(r,M[d],_),r+=2,t.setBigInt64(r,g(f),_),e=f*8,r+=8,s=0;s (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index d545a6e..eff4427 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e9d42bb --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.0-esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.0-esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),v=a(),g=m();var _=t()?function(t){var d,a,m,o,l,p,v,g,_,b,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,g=t.mode||"throw",I=(p=t.submode||[g]).length,d=i(m),_=0,(v=new r(new s(33+16*u+I))).setInt8(_,e?1:0),_+=1,v.setInt16(_,f[m],e),_+=2,v.setBigInt64(_,n(u),e),b=8*u,_+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16ed1da..0000000 --- a/lib/main.js +++ /dev/null @@ -1,219 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index aa7ab25..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,223 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( x.offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index a6620b4..20b21fc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-dataview": "^0.1.0", - "@stdlib/array-uint8": "^0.1.0", - "@stdlib/assert-has-bigint-support": "^0.1.0", - "@stdlib/assert-is-little-endian": "^0.1.0", - "@stdlib/bigint-ctor": "^0.1.0", - "@stdlib/ndarray-base-bytes-per-element": "^0.1.0", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/ndarray-index-modes": "^0.1.0", - "@stdlib/ndarray-orders": "^0.1.0", - "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-is-dataview": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.0.9", - "@stdlib/ndarray-base-ctor": "^0.0.6", - "@stdlib/ndarray-ctor": "^0.0.10", - "@stdlib/number-float64-base-from-int64-bytes": "^0.1.0", - "proxyquire": "^2.0.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", @@ -96,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c066cec --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 7097d4b8313d0331a9cc28aadc6c2efeed41c6b7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 10:01:40 +0000 Subject: [PATCH 047/124] 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 55bcafd..175de97 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@esm/index.mjs'; +import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@v0.1.0-esm/index.mjs'; ``` #### serialize( x ) @@ -141,7 +141,7 @@ import IS_LITTLE_ENDIAN from 'https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-li import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import Uint8Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs'; import fromInt64Bytes from 'https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-from-int64-bytes@esm/index.mjs'; -import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@esm/index.mjs'; +import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@v0.1.0-esm/index.mjs'; // Create an ndarray: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 98c483acb5b8d97476abf131881a1f467e6e90eb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 10:01:41 +0000 Subject: [PATCH 048/124] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 175de97..2b12199 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@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-serialize-meta-data/tags). For example, + ```javascript import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@v0.1.0-esm/index.mjs'; ``` @@ -141,7 +146,7 @@ import IS_LITTLE_ENDIAN from 'https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-li import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import Uint8Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs'; import fromInt64Bytes from 'https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-from-int64-bytes@esm/index.mjs'; -import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@v0.1.0-esm/index.mjs'; +import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@esm/index.mjs'; // Create an ndarray: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 99f6cbd3615fd01821fc8da86707434b37e75c8e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 14:04:40 +0000 Subject: [PATCH 049/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fba90bf..2f46ec2 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "@stdlib/ndarray-index-modes": "^0.1.0", "@stdlib/ndarray-orders": "^0.1.0", "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.1.0" + "@stdlib/types": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0" }, "devDependencies": { "@stdlib/array-float64": "^0.1.0", @@ -100,4 +101,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 1616f5345c6f188f53c67044610b56fee0024e0d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Oct 2023 21:58:29 +0000 Subject: [PATCH 050/124] Remove files --- index.d.ts | 102 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6284 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 eff4427..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e9d42bb..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.0-esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.0-esm/index.mjs";var f=d(),j=a(),h=m();var p=d(),v=a(),g=m();var _=t()?function(t){var d,a,m,o,l,p,v,g,_,b,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,g=t.mode||"throw",I=(p=t.submode||[g]).length,d=i(m),_=0,(v=new r(new s(33+16*u+I))).setInt8(_,e?1:0),_+=1,v.setInt16(_,f[m],e),_+=2,v.setBigInt64(_,n(u),e),b=8*u,_+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c066cec..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0694f8ddce2f34de74dfc4a625c3bd093f3e82ac Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Oct 2023 21:59:38 +0000 Subject: [PATCH 051/124] 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 | 45 +- benchmark/benchmark.js | 166 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 219 - lib/polyfill.js | 223 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 62 - test/test.js | 62 - test/test.main.js | 297 - test/test.polyfill.js | 297 - 45 files changed, 6205 insertions(+), 4905 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 5f044ff..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T04:17:48.967Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 e587e9c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -233,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -293,7 +286,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e8174da..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 68ca4eb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var B=p(function(Z,h){ -var _=require('@stdlib/assert-is-little-endian/dist'),A=require('@stdlib/array-buffer/dist'),T=require('@stdlib/array-dataview/dist'),g=require('@stdlib/bigint-ctor/dist'),L=require('@stdlib/ndarray-base-bytes-per-element/dist'),O=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=O(),P=R(),D=c();function Y(a){var i,n,m,d,I,l,q,t,v,r,e,f,u,s;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(d=a.dtype,I=a.shape,l=a.strides,f=I.length,v=a.mode||"throw",q=a.submode||[v],u=q.length,i=L(d),m=33+f*16+u,t=new T(new A(m)),r=0,t.setInt8(r,_?1:0),r+=1,t.setInt16(r,M[d],_),r+=2,t.setBigInt64(r,g(f),_),e=f*8,r+=8,s=0;s (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index d545a6e..eff4427 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..340f77b --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.0-esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.0-esm/index.mjs";var f=d(),j=a(),v=m();var h=d(),p=a(),g=m();var _=t()?function(t){var d,a,m,o,l,h,p,g,_,b,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,g=t.mode||"throw",I=(h=t.submode||[g]).length,d=i(m),_=0,(p=new r(new s(33+16*u+I))).setInt8(_,e?1:0),_+=1,p.setInt16(_,f[m],e),_+=2,p.setBigInt64(_,n(u),e),b=8*u,_+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16ed1da..0000000 --- a/lib/main.js +++ /dev/null @@ -1,219 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index aa7ab25..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,223 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( x.offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 2f46ec2..20b21fc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-dataview": "^0.1.0", - "@stdlib/array-uint8": "^0.1.0", - "@stdlib/assert-has-bigint-support": "^0.1.0", - "@stdlib/assert-is-little-endian": "^0.1.0", - "@stdlib/bigint-ctor": "^0.1.0", - "@stdlib/ndarray-base-bytes-per-element": "^0.1.0", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/ndarray-index-modes": "^0.1.0", - "@stdlib/ndarray-orders": "^0.1.0", - "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-is-dataview": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/number-float64-base-from-int64-bytes": "^0.1.0", - "proxyquire": "^2.0.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", @@ -96,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..34c2bd7 --- /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 4880141..0000000 --- a/test/dist/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../../dist/main.js' ); -var polyfill = require( './../../dist/polyfill.js' ); -var serialize = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../dist', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../dist', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 811807bf9559be348dd5b7bdb689c422d02e78ab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 17:32:36 +0000 Subject: [PATCH 052/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5db3985..573f655 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "@stdlib/ndarray-index-modes": "^0.1.1", "@stdlib/ndarray-orders": "^0.1.1", "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.1.0" + "@stdlib/types": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-float64": "^0.1.0", @@ -100,4 +101,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 9f6e4c81613f6abb1bf8dbfdba0e3a29750d6c3b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 6 Oct 2023 23:18:41 +0000 Subject: [PATCH 053/124] Remove files --- index.d.ts | 102 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6284 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 eff4427..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 340f77b..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.0-esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.0-esm/index.mjs";var f=d(),j=a(),v=m();var h=d(),p=a(),g=m();var _=t()?function(t){var d,a,m,o,l,h,p,g,_,b,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,g=t.mode||"throw",I=(h=t.submode||[g]).length,d=i(m),_=0,(p=new r(new s(33+16*u+I))).setInt8(_,e?1:0),_+=1,p.setInt16(_,f[m],e),_+=2,p.setBigInt64(_,n(u),e),b=8*u,_+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 34c2bd7..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 043fbf5b89ffc6427eac88454767edddc4efbc80 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 6 Oct 2023 23:19:42 +0000 Subject: [PATCH 054/124] 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 | 45 +- benchmark/benchmark.js | 166 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 219 - lib/polyfill.js | 223 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 297 - test/test.polyfill.js | 297 - 44 files changed, 6205 insertions(+), 4875 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 e587e9c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -233,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -293,7 +286,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e8174da..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 68ca4eb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var p=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var B=p(function(Z,h){ -var _=require('@stdlib/assert-is-little-endian/dist'),A=require('@stdlib/array-buffer/dist'),T=require('@stdlib/array-dataview/dist'),g=require('@stdlib/bigint-ctor/dist'),L=require('@stdlib/ndarray-base-bytes-per-element/dist'),O=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=O(),P=R(),D=c();function Y(a){var i,n,m,d,I,l,q,t,v,r,e,f,u,s;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(d=a.dtype,I=a.shape,l=a.strides,f=I.length,v=a.mode||"throw",q=a.submode||[v],u=q.length,i=L(d),m=33+f*16+u,t=new T(new A(m)),r=0,t.setInt8(r,_?1:0),r+=1,t.setInt16(r,M[d],_),r+=2,t.setBigInt64(r,g(f),_),e=f*8,r+=8,s=0;s (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index d545a6e..eff4427 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..518c6f0 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.1-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.1-esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.0-esm/index.mjs";var f=d(),j=a(),v=m();var h=d(),p=a(),g=m();var _=t()?function(t){var d,a,m,o,l,h,p,g,_,b,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,g=t.mode||"throw",I=(h=t.submode||[g]).length,d=i(m),_=0,(p=new r(new s(33+16*u+I))).setInt8(_,e?1:0),_+=1,p.setInt16(_,f[m],e),_+=2,p.setBigInt64(_,n(u),e),b=8*u,_+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 16ed1da..0000000 --- a/lib/main.js +++ /dev/null @@ -1,219 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index aa7ab25..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,223 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = x.dtype; - sh = x.shape; - st = x.strides; - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( x.offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ x.order ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 573f655..20b21fc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-dataview": "^0.1.0", - "@stdlib/array-uint8": "^0.1.0", - "@stdlib/assert-has-bigint-support": "^0.1.0", - "@stdlib/assert-is-little-endian": "^0.1.0", - "@stdlib/bigint-ctor": "^0.1.1", - "@stdlib/ndarray-base-bytes-per-element": "^0.1.0", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/ndarray-orders": "^0.1.1", - "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-is-dataview": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/number-float64-base-from-int64-bytes": "^0.1.0", - "proxyquire": "^2.0.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", @@ -96,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9474464 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From ee6508bde5b66eabb5c369dca0453d82a4f8ce4a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 20:26:15 +0000 Subject: [PATCH 055/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7713b57..c4ae9e1 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.1.1", "@stdlib/ndarray-orders": "^0.1.1", "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.1.0" + "@stdlib/types": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-float64": "^0.1.0", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 0e784f54e02e25d13d9c025dd9ca2f7c5a1f053c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 20:27:40 +0000 Subject: [PATCH 056/124] Remove files --- index.d.ts | 102 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6284 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 eff4427..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 518c6f0..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as d}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.1-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.1-esm/index.mjs";import{assign as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.0-esm/index.mjs";var f=d(),j=a(),v=m();var h=d(),p=a(),g=m();var _=t()?function(t){var d,a,m,o,l,h,p,g,_,b,u,I,y;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(m=t.dtype,o=t.shape,l=t.strides,u=o.length,g=t.mode||"throw",I=(h=t.submode||[g]).length,d=i(m),_=0,(p=new r(new s(33+16*u+I))).setInt8(_,e?1:0),_+=1,p.setInt16(_,f[m],e),_+=2,p.setBigInt64(_,n(u),e),b=8*u,_+=8,y=0;y (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( x.offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = x.dtype;\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( x.offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ x.order ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","dtype","shape","strides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","offset","order","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9474464..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6263f553725978e91e468e883d743f0f4cc4649e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 20:28:43 +0000 Subject: [PATCH 057/124] 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 | 45 +- benchmark/benchmark.js | 166 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 297 - test/test.polyfill.js | 297 - 44 files changed, 6205 insertions(+), 4890 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 e587e9c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -233,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -293,7 +286,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e8174da..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index d545a6e..eff4427 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..56b29c1 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@esm/index.mjs";import{assign as v}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.0-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,v,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),v=j(t,!1),f=l(t,!1),w=v.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index c4ae9e1..20b21fc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-dataview": "^0.1.0", - "@stdlib/array-uint8": "^0.1.0", - "@stdlib/assert-has-bigint-support": "^0.1.0", - "@stdlib/assert-is-little-endian": "^0.1.0", - "@stdlib/bigint-ctor": "^0.1.1", - "@stdlib/ndarray-base-bytes-per-element": "^0.1.0", - "@stdlib/ndarray-base-dtype": "github:stdlib-js/ndarray-base-dtype#main", - "@stdlib/ndarray-base-offset": "github:stdlib-js/ndarray-base-offset#main", - "@stdlib/ndarray-base-order": "github:stdlib-js/ndarray-base-order#main", - "@stdlib/ndarray-base-shape": "github:stdlib-js/ndarray-base-shape#main", - "@stdlib/ndarray-base-strides": "github:stdlib-js/ndarray-base-strides#main", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/ndarray-orders": "^0.1.1", - "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-is-dataview": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/number-float64-base-from-int64-bytes": "^0.1.0", - "proxyquire": "^2.0.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", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..833d9b9 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From cdf77640be0b50085db63b8be3d0d4800e9de08c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 17:04:40 +0000 Subject: [PATCH 058/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a3ddc07..1c6651e 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.1.1", "@stdlib/ndarray-orders": "^0.1.1", "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.1.0" + "@stdlib/types": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-float64": "^0.1.1", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From a30c51acbad1ced81f0e7fe13b31ce866fc4ae81 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 01:21:54 +0000 Subject: [PATCH 059/124] Remove files --- index.d.ts | 102 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6284 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 eff4427..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 56b29c1..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@esm/index.mjs";import{assign as v}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.0-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,v,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),v=j(t,!1),f=l(t,!1),w=v.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 833d9b9..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ab8086cc3a26bf35e80e6f4faf810ab1ee985b50 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 01:23:00 +0000 Subject: [PATCH 060/124] 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 | 45 +- benchmark/benchmark.js | 166 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 297 - test/test.polyfill.js | 297 - 45 files changed, 6205 insertions(+), 4899 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 af025ff..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T05:31:03.634Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 e587e9c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -233,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -293,7 +286,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e8174da..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index d545a6e..eff4427 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0eaaf22 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 1c6651e..20b21fc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-dataview": "^0.1.0", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/assert-has-bigint-support": "^0.1.1", - "@stdlib/assert-is-little-endian": "^0.1.1", - "@stdlib/bigint-ctor": "^0.1.1", - "@stdlib/ndarray-base-bytes-per-element": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-offset": "^0.1.0", - "@stdlib/ndarray-base-order": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-strides": "^0.1.0", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/ndarray-orders": "^0.1.1", - "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-dataview": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/number-float64-base-from-int64-bytes": "^0.1.0", - "proxyquire": "^2.0.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", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..939a6e9 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ae21825..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index a460721..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,297 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 3, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(3*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 67 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 710b8272b007013a830a4b929880211db5936031 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 Nov 2023 07:28:26 +0000 Subject: [PATCH 061/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4a15bd3..46f2993 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.1.1", "@stdlib/ndarray-orders": "^0.1.1", "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.2.0" + "@stdlib/types": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-float64": "^0.1.1", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From a22078ed86ee80c441a7df9b3fbfa734c318bb93 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 Nov 2023 07:31:04 +0000 Subject: [PATCH 062/124] Remove files --- index.d.ts | 102 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6284 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 eff4427..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0eaaf22..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 939a6e9..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 29646038efa0df84ef19f41a2a0a8822aa0a96f0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 Nov 2023 07:31:51 +0000 Subject: [PATCH 063/124] 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 | 45 +- benchmark/benchmark.js | 166 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 - test/test.polyfill.js | 299 - 44 files changed, 6205 insertions(+), 4897 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 e587e9c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -233,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -293,7 +286,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e8174da..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index d545a6e..eff4427 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0eaaf22 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 46f2993..20b21fc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-dataview": "^0.1.0", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/assert-has-bigint-support": "^0.1.1", - "@stdlib/assert-is-little-endian": "^0.1.1", - "@stdlib/bigint-ctor": "^0.1.1", - "@stdlib/ndarray-base-bytes-per-element": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-offset": "^0.1.0", - "@stdlib/ndarray-base-order": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-strides": "^0.1.0", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/ndarray-orders": "^0.1.1", - "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-dataview": "^0.1.1", - "@stdlib/bench": "^0.2.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/number-float64-base-from-int64-bytes": "^0.1.0", - "proxyquire": "^2.0.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", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6111ab8 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From c99be543be7f26473fbb7df8c5884f47eeda3555 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 13:15:41 +0000 Subject: [PATCH 064/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4a15bd3..46f2993 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.1.1", "@stdlib/ndarray-orders": "^0.1.1", "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.2.0" + "@stdlib/types": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-float64": "^0.1.1", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 7de72825e5a81b8072c392546cafa319587efaf8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 11:10:23 +0000 Subject: [PATCH 065/124] Remove files --- index.d.ts | 102 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6284 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 eff4427..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0eaaf22..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6111ab8..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 161c3e1ac626ac833dceec28b204633ad889ccca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 11:11:39 +0000 Subject: [PATCH 066/124] 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 | 45 +- benchmark/benchmark.js | 166 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 - test/test.polyfill.js | 299 - 45 files changed, 6205 insertions(+), 4898 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 827e53d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T05:35:41.647Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 e587e9c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -233,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -293,7 +286,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8926708..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e8174da..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index d545a6e..eff4427 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0eaaf22 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 46f2993..20b21fc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-dataview": "^0.1.0", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/assert-has-bigint-support": "^0.1.1", - "@stdlib/assert-is-little-endian": "^0.1.1", - "@stdlib/bigint-ctor": "^0.1.1", - "@stdlib/ndarray-base-bytes-per-element": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-offset": "^0.1.0", - "@stdlib/ndarray-base-order": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-strides": "^0.1.0", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/ndarray-orders": "^0.1.1", - "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-dataview": "^0.1.1", - "@stdlib/bench": "^0.2.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/number-float64-base-from-int64-bytes": "^0.1.0", - "proxyquire": "^2.0.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", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2016111 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From d64b1c30ba76122a4e08ab6dd773d09c91b9bb8b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 07:54:45 +0000 Subject: [PATCH 067/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 40b2fe1..5b2af5c 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.1.1", "@stdlib/ndarray-orders": "^0.1.1", "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.2.0" + "@stdlib/types": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-float64": "^0.1.1", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From b5ba657ebaae1e800e322709a4936dfd6fb0b9e3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:33:50 +0000 Subject: [PATCH 068/124] Remove files --- index.d.ts | 102 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6284 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 eff4427..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0eaaf22..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2016111..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 04ac4fc949033536ef59af9b4a0756ee43340de8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:34:23 +0000 Subject: [PATCH 069/124] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 - test/test.polyfill.js | 299 - 46 files changed, 6205 insertions(+), 4904 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 7677cf6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:05:14.231Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 8cb33d8..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -233,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -293,7 +286,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e8174da..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index d545a6e..eff4427 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..efacf6f --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 5b2af5c..20b21fc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-dataview": "^0.1.0", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/assert-has-bigint-support": "^0.1.1", - "@stdlib/assert-is-little-endian": "^0.1.1", - "@stdlib/bigint-ctor": "^0.1.1", - "@stdlib/ndarray-base-bytes-per-element": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-offset": "^0.1.0", - "@stdlib/ndarray-base-order": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-strides": "^0.1.0", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/ndarray-orders": "^0.1.1", - "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-dataview": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/number-float64-base-from-int64-bytes": "^0.1.0", - "proxyquire": "^2.0.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", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3db49f5 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 1c7ed6b9dc0e11a403a392dfd61a1f3857973702 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 08:24:38 +0000 Subject: [PATCH 070/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 40b2fe1..5b2af5c 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.1.1", "@stdlib/ndarray-orders": "^0.1.1", "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.2.0" + "@stdlib/types": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-float64": "^0.1.1", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From e58f75ab1f61077189f87f2c4d8373062f3dd5cd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:50:49 +0000 Subject: [PATCH 071/124] Remove files --- index.d.ts | 102 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6284 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 eff4427..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index efacf6f..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3db49f5..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 824de12485c999fe75f7ad5ad40f972ef0c60895 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:51:13 +0000 Subject: [PATCH 072/124] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 - test/test.polyfill.js | 299 - 46 files changed, 6205 insertions(+), 4909 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 bfab4b7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T05:53:44.090Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 8cb33d8..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -235,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -298,7 +289,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ee81373..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f4b475b..d5c20b2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..efacf6f --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 5b2af5c..20b21fc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-dataview": "^0.1.0", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/assert-has-bigint-support": "^0.1.1", - "@stdlib/assert-is-little-endian": "^0.1.1", - "@stdlib/bigint-ctor": "^0.1.1", - "@stdlib/ndarray-base-bytes-per-element": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-offset": "^0.1.0", - "@stdlib/ndarray-base-order": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-strides": "^0.1.0", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/ndarray-orders": "^0.1.1", - "@stdlib/number-float64-base-to-int64-bytes": "^0.1.0", - "@stdlib/types": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-dataview": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/number-float64-base-from-int64-bytes": "^0.1.0", - "proxyquire": "^2.0.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", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..378b0b9 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 13a459a56c4f6393188d0a6aff8ff0ce60c07382 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 23:56:29 +0000 Subject: [PATCH 073/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c136f27..b3ae423 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.2.0", "@stdlib/ndarray-orders": "^0.2.0", "@stdlib/number-float64-base-to-int64-bytes": "^0.2.0", - "@stdlib/types": "^0.3.1" + "@stdlib/types": "^0.3.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0" }, "devDependencies": { "@stdlib/array-float64": "^0.2.0", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From ec1592bbe882f79635f5681788d9268461490a32 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 02:48:35 +0000 Subject: [PATCH 074/124] Remove files --- index.d.ts | 102 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6284 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 d5c20b2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index efacf6f..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.1.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.1.0-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.1.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.1.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.1.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 378b0b9..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7e1d42354e69b68080a7576c13e3ecdde42cbff9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 02:49:17 +0000 Subject: [PATCH 075/124] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 - test/test.polyfill.js | 299 - 45 files changed, 6205 insertions(+), 4912 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 b22f7bd..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -235,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -298,7 +289,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ee81373..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f4b475b..d5c20b2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e34b5dc --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.0-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.2.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.0-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.0-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.0-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index b3ae423..7804421 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.0", - "@stdlib/array-dataview": "^0.2.0", - "@stdlib/array-uint8": "^0.2.0", - "@stdlib/assert-has-bigint-support": "^0.2.0", - "@stdlib/assert-is-little-endian": "^0.2.0", - "@stdlib/bigint-ctor": "^0.2.0", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.0", - "@stdlib/ndarray-base-dtype": "^0.2.0", - "@stdlib/ndarray-base-offset": "^0.2.0", - "@stdlib/ndarray-base-order": "^0.2.0", - "@stdlib/ndarray-base-shape": "^0.2.0", - "@stdlib/ndarray-base-strides": "^0.2.0", - "@stdlib/ndarray-dtypes": "^0.2.0", - "@stdlib/ndarray-index-modes": "^0.2.0", - "@stdlib/ndarray-orders": "^0.2.0", - "@stdlib/number-float64-base-to-int64-bytes": "^0.2.0", - "@stdlib/types": "^0.3.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.0", - "@stdlib/assert-is-dataview": "^0.2.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.2.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/number-float64-base-from-int64-bytes": "^0.2.0", - "proxyquire": "^2.0.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", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..fa64e28 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From a049e9c2433627df93c2ae428a385c4e25865be0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:33:08 +0000 Subject: [PATCH 076/124] 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 30f099b..175e0d5 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@esm/index.mjs'; +import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@v0.2.0-esm/index.mjs'; ``` #### serialize( x ) @@ -141,7 +141,7 @@ import IS_LITTLE_ENDIAN from 'https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-li import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import Uint8Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs'; import fromInt64Bytes from 'https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-from-int64-bytes@esm/index.mjs'; -import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@esm/index.mjs'; +import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@v0.2.0-esm/index.mjs'; // Create an ndarray: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 7ae45c89e9489ee931f78adcf4cc4056b3629c78 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:33:09 +0000 Subject: [PATCH 077/124] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 175e0d5..39ed98a 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@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-serialize-meta-data/tags). For example, + ```javascript import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@v0.2.0-esm/index.mjs'; ``` @@ -141,7 +146,7 @@ import IS_LITTLE_ENDIAN from 'https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-li import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import Uint8Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs'; import fromInt64Bytes from 'https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-from-int64-bytes@esm/index.mjs'; -import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@v0.2.0-esm/index.mjs'; +import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@esm/index.mjs'; // Create an ndarray: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From d5a139e744faeca00d5a5e82c2c128a3b5cf1e54 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 18:52:00 +0000 Subject: [PATCH 078/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a2f9eba..a064960 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.2.1", "@stdlib/ndarray-orders": "^0.2.1", "@stdlib/number-float64-base-to-int64-bytes": "^0.2.1", - "@stdlib/types": "^0.3.2" + "@stdlib/types": "^0.3.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/array-float64": "^0.2.1", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 208e069be60379dcce8baf419078ee0548f2b4b6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:05:27 +0000 Subject: [PATCH 079/124] Remove files --- index.d.ts | 102 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6284 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 d5c20b2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e34b5dc..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.0-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.2.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.0-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.0-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.0-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":";;8/CAuCA,IAAIA,EAASC,IACTC,EAASC,IACTC,EAAQC,ICDZ,IAAIL,EAASC,IACTC,EAASC,IACTC,EAAQC,ICYZ,IAAAC,EATKC,IFmFL,SAAoBC,GACnB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKb,EAAEc,wBACN,OAAOd,EAAEc,0BAqCV,IAlCAX,EAAKY,EAAUf,GACfI,EAAKY,EAAUhB,GAAG,GAClBK,EAAKY,EAAYjB,GAAG,GACpBW,EAAIP,EAAGc,OAGPV,EAAIR,EAAEmB,MAAQ,QAEdP,GADAN,EAAKN,EAAEoB,SAAW,CAAEZ,IACbU,OAGPjB,EAASoB,EAAiBlB,GAS1BM,EAAI,GAHJF,EAAI,IAAIe,EAAU,IAAIC,EAHhB,GAAQ,GAAFZ,EAAQC,KAOlBY,QAASf,EAAG,EAAuB,EAAI,GAGzCA,GAAK,EACLF,EAAEkB,SAAUhB,EAAGjB,EAAQW,GAAMuB,GAG7BjB,GAAK,EACLF,EAAEoB,YAAalB,EAAGmB,EAAQjB,GAAKe,GAG/BhB,EAAQ,EAAJC,EACJF,GAAK,EACCI,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAEoB,YAAalB,EAAGmB,EAAQxB,EAAGS,IAAMa,GACnCnB,EAAEoB,YAAalB,EAAEC,EAAGkB,EAAQvB,EAAGQ,GAAGZ,GAAUyB,GAC5CjB,GAAK,EAoBN,IAjBAA,GAAKC,EACLH,EAAEoB,YAAalB,EAAGmB,EAAQC,EAAW7B,GAAIC,GAAUyB,GAGnDjB,GAAK,EACLF,EAAEiB,QAASf,EAAGf,EAAQoC,EAAU9B,KAGhCS,GAAK,EACLF,EAAEiB,QAASf,EAAGb,EAAOY,IAGrBC,GAAK,EACLF,EAAEoB,YAAalB,EAAGmB,EAAQhB,GAAKc,GAG/BjB,GAAK,EACCI,EAAI,EAAGA,EAAID,EAAGC,IACnBN,EAAEiB,QAASf,EAAGb,EAAOU,EAAGO,KACxBJ,GAAK,EASN,OANAP,EAAO,EACFF,EAAE+B,QACN7B,GAAUF,EAAE+B,MAAmB,SAAA,EAAI,GAEpCxB,EAAEyB,SAAUvB,EAAGP,EAAMwB,GAEdnB,CACR,ECxFA,SAAoBP,GACnB,IAAIC,EACAgC,EACA/B,EAEAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKb,EAAEc,wBACN,OAAOd,EAAEc,0BAsCV,IAnCAX,EAAKY,EAAUf,GACfI,EAAKY,EAAUhB,GAAG,GAClBK,EAAKY,EAAYjB,GAAG,GACpBW,EAAIP,EAAGc,OAGPV,EAAIR,EAAEmB,MAAQ,QAEdP,GADAN,EAAKN,EAAEoB,SAAW,CAAEZ,IACbU,OAGPjB,EAASoB,EAAiBlB,GAM1BI,EAAI,IAAIe,EAAU,IAAIC,EAHhB,GAAQ,GAAFZ,EAAQC,IAIpBqB,EAAQ,IAAIC,EAAY3B,EAAE4B,QAG1B1B,EAAI,EACJF,EAAEiB,QAASf,EAAG,EAAuB,EAAI,GAGzCA,GAAK,EACLF,EAAEkB,SAAUhB,EAAGjB,EAAQW,GAAMuB,GAI7BU,EAAqBzB,EAAGsB,EAAO,EAD/BxB,GAAK,GAILC,EAAQ,EAAJC,EACJF,GAAK,EACCI,EAAI,EAAGA,EAAIF,EAAGE,IACnBuB,EAAqBhC,EAAGS,GAAIoB,EAAO,EAAGxB,GACtC2B,EAAqB/B,EAAGQ,GAAGZ,EAAQgC,EAAO,EAAGxB,EAAEC,GAC/CD,GAAK,EAoBN,IAjBAA,GAAKC,EACL0B,EAAqBP,EAAW7B,GAAIC,EAAQgC,EAAO,EAAGxB,GAGtDA,GAAK,EACLF,EAAEiB,QAASf,EAAGf,EAAQoC,EAAU9B,KAGhCS,GAAK,EACLF,EAAEiB,QAASf,EAAGb,EAAOY,IAIrB4B,EAAqBxB,EAAGqB,EAAO,EAD/BxB,GAAK,GAILA,GAAK,EACCI,EAAI,EAAGA,EAAID,EAAGC,IACnBN,EAAEiB,QAASf,EAAGb,EAAOU,EAAGO,KACxBJ,GAAK,EASN,OANAP,EAAO,EACFF,EAAE+B,QACN7B,GAAUF,EAAE+B,MAAmB,SAAA,EAAI,GAEpCxB,EAAEyB,SAAUvB,EAAGP,EAAMwB,GAEdnB,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fa64e28..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c1372218dab8f37dadccf83cb088712618a52400 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:05:52 +0000 Subject: [PATCH 080/124] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 -- test/test.polyfill.js | 299 -- 45 files changed, 4870 insertions(+), 4906 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6ca805a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -235,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -298,7 +289,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ee81373..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f4b475b..d5c20b2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6421bd9 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.1-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.2.1-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index a064960..4b3c0b8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.1", - "@stdlib/array-dataview": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/assert-has-bigint-support": "^0.2.1", - "@stdlib/assert-is-little-endian": "^0.2.1", - "@stdlib/bigint-ctor": "^0.2.1", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.1", - "@stdlib/ndarray-base-dtype": "^0.2.1", - "@stdlib/ndarray-base-offset": "^0.2.1", - "@stdlib/ndarray-base-order": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/ndarray-dtypes": "^0.2.1", - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/ndarray-orders": "^0.2.1", - "@stdlib/number-float64-base-to-int64-bytes": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-dataview": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.0", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.0", - "@stdlib/number-float64-base-from-int64-bytes": "^0.2.1", - "proxyquire": "^2.0.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", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2002958 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 0c59c88e388ac1b78e13a59676dd1e9c1867738f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:15:49 +0000 Subject: [PATCH 081/124] 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 b0f6a0e..70fc6b9 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@esm/index.mjs'; +import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@v0.2.1-esm/index.mjs'; ``` #### serialize( x ) @@ -141,7 +141,7 @@ import IS_LITTLE_ENDIAN from 'https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-li import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import Uint8Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs'; import fromInt64Bytes from 'https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-from-int64-bytes@esm/index.mjs'; -import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@esm/index.mjs'; +import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@v0.2.1-esm/index.mjs'; // Create an ndarray: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From b17f65212718cc5efb7220907fd19aa65c37e2c4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:15:49 +0000 Subject: [PATCH 082/124] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 70fc6b9..62efac4 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@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-serialize-meta-data/tags). For example, + ```javascript import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@v0.2.1-esm/index.mjs'; ``` @@ -141,7 +146,7 @@ import IS_LITTLE_ENDIAN from 'https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-li import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import Uint8Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@esm/index.mjs'; import fromInt64Bytes from 'https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-from-int64-bytes@esm/index.mjs'; -import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@v0.2.1-esm/index.mjs'; +import serialize from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-serialize-meta-data@esm/index.mjs'; // Create an ndarray: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From efae7403b21c079d367dc41b5ad9acb2fcbf4bf6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 07:44:53 +0000 Subject: [PATCH 083/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 97b7730..6a6650a 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.2.1", "@stdlib/ndarray-orders": "^0.2.1", "@stdlib/number-float64-base-to-int64-bytes": "^0.2.1", - "@stdlib/types": "^0.3.2" + "@stdlib/types": "^0.3.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/array-float64": "^0.2.1", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 631b4648c7a0c4497b85ca68a1d91ef7c3466926 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:28:04 +0000 Subject: [PATCH 084/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4949 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 d5c20b2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6421bd9..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.1-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.2.1-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":";;8/CAuCA,IAAIA,EAASC,IACTC,EAASC,IACTC,EAAQC,ICDZ,IAAIL,EAASC,IACTC,EAASC,IACTC,EAAQC,ICYZ,IAAAC,EATKC,IFmFL,SAAoBC,GACnB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKb,EAAEc,wBACN,OAAOd,EAAEc,0BAqCV,IAlCAX,EAAKY,EAAUf,GACfI,EAAKY,EAAUhB,GAAG,GAClBK,EAAKY,EAAYjB,GAAG,GACpBW,EAAIP,EAAGc,OAGPV,EAAIR,EAAEmB,MAAQ,QAEdP,GADAN,EAAKN,EAAEoB,SAAW,CAAEZ,IACbU,OAGPjB,EAASoB,EAAiBlB,GAS1BM,EAAI,GAHJF,EAAI,IAAIe,EAAU,IAAIC,EAHhB,GAAQ,GAAFZ,EAAQC,KAOlBY,QAASf,EAAG,EAAuB,EAAI,GAGzCA,GAAK,EACLF,EAAEkB,SAAUhB,EAAGjB,EAAQW,GAAMuB,GAG7BjB,GAAK,EACLF,EAAEoB,YAAalB,EAAGmB,EAAQjB,GAAKe,GAG/BhB,EAAQ,EAAJC,EACJF,GAAK,EACCI,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAEoB,YAAalB,EAAGmB,EAAQxB,EAAGS,IAAMa,GACnCnB,EAAEoB,YAAalB,EAAEC,EAAGkB,EAAQvB,EAAGQ,GAAGZ,GAAUyB,GAC5CjB,GAAK,EAoBN,IAjBAA,GAAKC,EACLH,EAAEoB,YAAalB,EAAGmB,EAAQC,EAAW7B,GAAIC,GAAUyB,GAGnDjB,GAAK,EACLF,EAAEiB,QAASf,EAAGf,EAAQoC,EAAU9B,KAGhCS,GAAK,EACLF,EAAEiB,QAASf,EAAGb,EAAOY,IAGrBC,GAAK,EACLF,EAAEoB,YAAalB,EAAGmB,EAAQhB,GAAKc,GAG/BjB,GAAK,EACCI,EAAI,EAAGA,EAAID,EAAGC,IACnBN,EAAEiB,QAASf,EAAGb,EAAOU,EAAGO,KACxBJ,GAAK,EASN,OANAP,EAAO,EACFF,EAAE+B,QACN7B,GAAUF,EAAE+B,MAAmB,SAAA,EAAI,GAEpCxB,EAAEyB,SAAUvB,EAAGP,EAAMwB,GAEdnB,CACR,ECxFA,SAAoBP,GACnB,IAAIC,EACAgC,EACA/B,EAEAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKb,EAAEc,wBACN,OAAOd,EAAEc,0BAsCV,IAnCAX,EAAKY,EAAUf,GACfI,EAAKY,EAAUhB,GAAG,GAClBK,EAAKY,EAAYjB,GAAG,GACpBW,EAAIP,EAAGc,OAGPV,EAAIR,EAAEmB,MAAQ,QAEdP,GADAN,EAAKN,EAAEoB,SAAW,CAAEZ,IACbU,OAGPjB,EAASoB,EAAiBlB,GAM1BI,EAAI,IAAIe,EAAU,IAAIC,EAHhB,GAAQ,GAAFZ,EAAQC,IAIpBqB,EAAQ,IAAIC,EAAY3B,EAAE4B,QAG1B1B,EAAI,EACJF,EAAEiB,QAASf,EAAG,EAAuB,EAAI,GAGzCA,GAAK,EACLF,EAAEkB,SAAUhB,EAAGjB,EAAQW,GAAMuB,GAI7BU,EAAqBzB,EAAGsB,EAAO,EAD/BxB,GAAK,GAILC,EAAQ,EAAJC,EACJF,GAAK,EACCI,EAAI,EAAGA,EAAIF,EAAGE,IACnBuB,EAAqBhC,EAAGS,GAAIoB,EAAO,EAAGxB,GACtC2B,EAAqB/B,EAAGQ,GAAGZ,EAAQgC,EAAO,EAAGxB,EAAEC,GAC/CD,GAAK,EAoBN,IAjBAA,GAAKC,EACL0B,EAAqBP,EAAW7B,GAAIC,EAAQgC,EAAO,EAAGxB,GAGtDA,GAAK,EACLF,EAAEiB,QAASf,EAAGf,EAAQoC,EAAU9B,KAGhCS,GAAK,EACLF,EAAEiB,QAASf,EAAGb,EAAOY,IAIrB4B,EAAqBxB,EAAGqB,EAAO,EAD/BxB,GAAK,GAILA,GAAK,EACCI,EAAI,EAAGA,EAAID,EAAGC,IACnBN,EAAEiB,QAASf,EAAGb,EAAOU,EAAGO,KACxBJ,GAAK,EASN,OANAP,EAAO,EACFF,EAAE+B,QACN7B,GAAUF,EAAE+B,MAAmB,SAAA,EAAI,GAEpCxB,EAAEyB,SAAUvB,EAAGP,EAAMwB,GAEdnB,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2002958..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ccd3d2bacaf5384163237a7abc7196855a9d88a6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:28:20 +0000 Subject: [PATCH 085/124] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 -- test/test.polyfill.js | 299 -- 46 files changed, 4870 insertions(+), 4908 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 5b2aac5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T05:35:44.500Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6ca805a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -235,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -298,7 +289,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ee81373..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f4b475b..d5c20b2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..009b315 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.1-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.2.1-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 6a6650a..4b3c0b8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.1", - "@stdlib/array-dataview": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/assert-has-bigint-support": "^0.2.1", - "@stdlib/assert-is-little-endian": "^0.2.1", - "@stdlib/bigint-ctor": "^0.2.1", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.1", - "@stdlib/ndarray-base-dtype": "^0.2.1", - "@stdlib/ndarray-base-offset": "^0.2.1", - "@stdlib/ndarray-base-order": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/ndarray-dtypes": "^0.2.1", - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/ndarray-orders": "^0.2.1", - "@stdlib/number-float64-base-to-int64-bytes": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-dataview": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/number-float64-base-from-int64-bytes": "^0.2.1", - "proxyquire": "^2.0.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", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6149946 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 12c74cb27e02d67c96b51f10faeabff4959a25b8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:03:58 +0000 Subject: [PATCH 086/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 97b7730..6a6650a 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.2.1", "@stdlib/ndarray-orders": "^0.2.1", "@stdlib/number-float64-base-to-int64-bytes": "^0.2.1", - "@stdlib/types": "^0.3.2" + "@stdlib/types": "^0.3.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/array-float64": "^0.2.1", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 13cf2a9c9200833b813ad480ec5fd6e7a913f6d5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:19:52 +0000 Subject: [PATCH 087/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4949 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 d5c20b2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 009b315..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.1-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.2.1-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6149946..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 908dfda72ddad1583457d96a320eb37d65ed531a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:20:08 +0000 Subject: [PATCH 088/124] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 -- test/test.polyfill.js | 299 -- 46 files changed, 4870 insertions(+), 4911 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 fa3723e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T04:54:38.799Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6ca805a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -235,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -298,7 +289,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ee81373..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f4b475b..d5c20b2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..009b315 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.1-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.2.1-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 6a6650a..4b3c0b8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.1", - "@stdlib/array-dataview": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/assert-has-bigint-support": "^0.2.1", - "@stdlib/assert-is-little-endian": "^0.2.1", - "@stdlib/bigint-ctor": "^0.2.1", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.1", - "@stdlib/ndarray-base-dtype": "^0.2.1", - "@stdlib/ndarray-base-offset": "^0.2.1", - "@stdlib/ndarray-base-order": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/ndarray-dtypes": "^0.2.1", - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/ndarray-orders": "^0.2.1", - "@stdlib/number-float64-base-to-int64-bytes": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-dataview": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/number-float64-base-from-int64-bytes": "^0.2.1", - "proxyquire": "^2.0.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", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6149946 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 1c316b7bc644c63f3646a051bf9532e2c6755a6d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:20:15 +0000 Subject: [PATCH 089/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 97b7730..6a6650a 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.2.1", "@stdlib/ndarray-orders": "^0.2.1", "@stdlib/number-float64-base-to-int64-bytes": "^0.2.1", - "@stdlib/types": "^0.3.2" + "@stdlib/types": "^0.3.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/array-float64": "^0.2.1", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 2a9a8d8e93d11a19f665f5b8d4b282da959cc768 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:41:41 +0000 Subject: [PATCH 090/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4949 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 d5c20b2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 009b315..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.1-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.2.1-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6149946..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b40ac55948f59afa5586b3319dc112e8c9aab6bb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:42:24 +0000 Subject: [PATCH 091/124] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 -- test/test.polyfill.js | 299 -- 45 files changed, 4870 insertions(+), 4912 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6ca805a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -235,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -298,7 +289,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ee81373..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f4b475b..d5c20b2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..009b315 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.1-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.2.1-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 6a6650a..4b3c0b8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.1", - "@stdlib/array-dataview": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/assert-has-bigint-support": "^0.2.1", - "@stdlib/assert-is-little-endian": "^0.2.1", - "@stdlib/bigint-ctor": "^0.2.1", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.1", - "@stdlib/ndarray-base-dtype": "^0.2.1", - "@stdlib/ndarray-base-offset": "^0.2.1", - "@stdlib/ndarray-base-order": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/ndarray-dtypes": "^0.2.1", - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/ndarray-orders": "^0.2.1", - "@stdlib/number-float64-base-to-int64-bytes": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-dataview": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/number-float64-base-from-int64-bytes": "^0.2.1", - "proxyquire": "^2.0.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", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6149946 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 99f5c4432495cbb446a5e54775f365203240299c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:22:42 +0000 Subject: [PATCH 092/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 261a153..1da2278 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^0.2.2", "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.3.2" + "@stdlib/types": "^0.3.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 07261f9a3a036dab1cac31e23071a8cf1a6b4b14 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:29:19 +0000 Subject: [PATCH 093/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4949 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 d5c20b2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 009b315..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.1-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.2.1-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.1-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.1-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6149946..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7269818b226ae3898897ea46fd4db29b274cfa57 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:29:45 +0000 Subject: [PATCH 094/124] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 189 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 -- test/test.polyfill.js | 299 -- 45 files changed, 4870 insertions(+), 5109 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6ca805a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -235,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -298,7 +289,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ee81373..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f4b475b..d5c20b2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6f5fbf8 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 1da2278..4b0d1cb 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/array-dataview": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-has-bigint-support": "^0.2.2", - "@stdlib/assert-is-little-endian": "^0.2.2", - "@stdlib/bigint-ctor": "^0.2.2", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^0.2.2", - "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-dataview": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/number-float64-base-from-int64-bytes": "^0.2.2", - "proxyquire": "^2.0.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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ebdce96 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From d706b7b01f638ee6d819c58f349ae00f5e98d28b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 07:50:47 +0000 Subject: [PATCH 095/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 961efb6..6453804 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^0.2.2", "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.3.2" + "@stdlib/types": "^0.3.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From acd19672e00ab4981fdb6071cfa0f9fa6e3001e8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:45:14 +0000 Subject: [PATCH 096/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4949 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 d5c20b2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6f5fbf8..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ebdce96..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8dec7515e2f5ce4ece637c1fdd13ed03c61119f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:45:36 +0000 Subject: [PATCH 097/124] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 -- test/test.polyfill.js | 299 -- 46 files changed, 4870 insertions(+), 5059 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 61d6307..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T05:45:33.814Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6ca805a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -235,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -298,7 +289,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ee81373..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f4b475b..d5c20b2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2b6cb64 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 6453804..4b0d1cb 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/array-dataview": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-has-bigint-support": "^0.2.2", - "@stdlib/assert-is-little-endian": "^0.2.2", - "@stdlib/bigint-ctor": "^0.2.2", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^0.2.2", - "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-dataview": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/number-float64-base-from-int64-bytes": "^0.2.2", - "proxyquire": "^2.0.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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b99bdf3 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From e18bfd585aac22f9708743a21e4acfde9594ed6e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:14:07 +0000 Subject: [PATCH 098/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 82db5d1..0b66a04 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^0.2.2", "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.1" + "@stdlib/types": "^0.4.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 4ca1880fc2acaf078fe2549e2394a815b58fde74 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:34:49 +0000 Subject: [PATCH 099/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4949 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 d5c20b2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2b6cb64..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b99bdf3..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 438a08bbc653d9b0697238adbde2632aabc4d947 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:35:29 +0000 Subject: [PATCH 100/124] 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 | 188 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 -- test/test.polyfill.js | 299 -- 46 files changed, 4870 insertions(+), 5109 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 bae9991..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T06:11:39.965Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6ca805a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -235,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -298,7 +289,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ee81373..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 898766a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte) - - dt: data type (2 bytes) - - ndims: number of dimensions (8 bytes) - - shape: shape (ndims*8 bytes) - - strides: strides in units of bytes (ndims*8 bytes) - - offset: index offset in units of bytes (8 bytes) - - ord: array order (1 byte) - - mode: index mode (1 byte) - - nsubmodes: number of subscript index modes (8 bytes) - - submodes: subscript index modes (nsubmodes*1 bytes) - - flags: flags (4 bytes) - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f4b475b..d5c20b2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2b6cb64 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 0b66a04..4b0d1cb 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/array-dataview": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-has-bigint-support": "^0.2.2", - "@stdlib/assert-is-little-endian": "^0.2.2", - "@stdlib/bigint-ctor": "^0.2.2", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^0.2.2", - "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-dataview": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/number-float64-base-from-int64-bytes": "^0.2.2", - "proxyquire": "^2.0.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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b99bdf3 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 4d9c5c0edcd5cfedad50bbf80fc432f1ddd9abc8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 21 Sep 2024 21:42:04 +0000 Subject: [PATCH 101/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 82db5d1..0b66a04 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^0.2.2", "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.1" + "@stdlib/types": "^0.4.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 5f74fbde1eefff9852d72d4e96f28216dfb9cbe4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 21 Sep 2024 22:01:22 +0000 Subject: [PATCH 102/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4949 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 d5c20b2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2b6cb64..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b99bdf3..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 39123cf1ff43f1819d33dd01b961f4c37dab280f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 21 Sep 2024 22:01:56 +0000 Subject: [PATCH 103/124] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 222 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 -- test/test.polyfill.js | 299 -- 45 files changed, 4870 insertions(+), 5142 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6ca805a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -235,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -298,7 +289,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ee81373..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 31f573a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte). - - dt: data type (2 bytes). - - ndims: number of dimensions (8 bytes). - - shape: shape (ndims*8 bytes). - - strides: strides in units of bytes (ndims*8 bytes). - - offset: index offset in units of bytes (8 bytes). - - ord: array order (1 byte). - - mode: index mode (1 byte). - - nsubmodes: number of subscript index modes (8 bytes). - - submodes: subscript index modes (nsubmodes*1 bytes). - - flags: flags (4 bytes). - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e3d3ddb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f4b475b..d5c20b2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2b6cb64 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":";;8/CAuCA,IAAIA,EAASC,IACTC,EAASC,IACTC,EAAQC,ICDZ,IAAIL,EAASC,IACTC,EAASC,IACTC,EAAQC,ICYZ,IAAAC,EATKC,IFmFL,SAAoBC,GACnB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKb,EAAEc,wBACN,OAAOd,EAAEc,0BAqCV,IAlCAX,EAAKY,EAAUf,GACfI,EAAKY,EAAUhB,GAAG,GAClBK,EAAKY,EAAYjB,GAAG,GACpBW,EAAIP,EAAGc,OAGPV,EAAIR,EAAEmB,MAAQ,QAEdP,GADAN,EAAKN,EAAEoB,SAAW,CAAEZ,IACbU,OAGPjB,EAASoB,EAAiBlB,GAS1BM,EAAI,GAHJF,EAAI,IAAIe,EAAU,IAAIC,EAHhB,GAAQ,GAAFZ,EAAQC,KAOlBY,QAASf,EAAG,EAAuB,EAAI,GAGzCA,GAAK,EACLF,EAAEkB,SAAUhB,EAAGjB,EAAQW,GAAMuB,GAG7BjB,GAAK,EACLF,EAAEoB,YAAalB,EAAGmB,EAAQjB,GAAKe,GAG/BhB,EAAQ,EAAJC,EACJF,GAAK,EACCI,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAEoB,YAAalB,EAAGmB,EAAQxB,EAAGS,IAAMa,GACnCnB,EAAEoB,YAAalB,EAAEC,EAAGkB,EAAQvB,EAAGQ,GAAGZ,GAAUyB,GAC5CjB,GAAK,EAoBN,IAjBAA,GAAKC,EACLH,EAAEoB,YAAalB,EAAGmB,EAAQC,EAAW7B,GAAIC,GAAUyB,GAGnDjB,GAAK,EACLF,EAAEiB,QAASf,EAAGf,EAAQoC,EAAU9B,KAGhCS,GAAK,EACLF,EAAEiB,QAASf,EAAGb,EAAOY,IAGrBC,GAAK,EACLF,EAAEoB,YAAalB,EAAGmB,EAAQhB,GAAKc,GAG/BjB,GAAK,EACCI,EAAI,EAAGA,EAAID,EAAGC,IACnBN,EAAEiB,QAASf,EAAGb,EAAOU,EAAGO,KACxBJ,GAAK,EASN,OANAP,EAAO,EACFF,EAAE+B,QACN7B,GAAUF,EAAE+B,MAAmB,SAAA,EAAI,GAEpCxB,EAAEyB,SAAUvB,EAAGP,EAAMwB,GAEdnB,CACR,ECxFA,SAAoBP,GACnB,IAAIC,EACAgC,EACA/B,EAEAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKb,EAAEc,wBACN,OAAOd,EAAEc,0BAsCV,IAnCAX,EAAKY,EAAUf,GACfI,EAAKY,EAAUhB,GAAG,GAClBK,EAAKY,EAAYjB,GAAG,GACpBW,EAAIP,EAAGc,OAGPV,EAAIR,EAAEmB,MAAQ,QAEdP,GADAN,EAAKN,EAAEoB,SAAW,CAAEZ,IACbU,OAGPjB,EAASoB,EAAiBlB,GAM1BI,EAAI,IAAIe,EAAU,IAAIC,EAHhB,GAAQ,GAAFZ,EAAQC,IAIpBqB,EAAQ,IAAIC,EAAY3B,EAAE4B,QAG1B1B,EAAI,EACJF,EAAEiB,QAASf,EAAG,EAAuB,EAAI,GAGzCA,GAAK,EACLF,EAAEkB,SAAUhB,EAAGjB,EAAQW,GAAMuB,GAI7BU,EAAqBzB,EAAGsB,EAAO,EAD/BxB,GAAK,GAILC,EAAQ,EAAJC,EACJF,GAAK,EACCI,EAAI,EAAGA,EAAIF,EAAGE,IACnBuB,EAAqBhC,EAAGS,GAAIoB,EAAO,EAAGxB,GACtC2B,EAAqB/B,EAAGQ,GAAGZ,EAAQgC,EAAO,EAAGxB,EAAEC,GAC/CD,GAAK,EAoBN,IAjBAA,GAAKC,EACL0B,EAAqBP,EAAW7B,GAAIC,EAAQgC,EAAO,EAAGxB,GAGtDA,GAAK,EACLF,EAAEiB,QAASf,EAAGf,EAAQoC,EAAU9B,KAGhCS,GAAK,EACLF,EAAEiB,QAASf,EAAGb,EAAOY,IAIrB4B,EAAqBxB,EAAGqB,EAAO,EAD/BxB,GAAK,GAILA,GAAK,EACCI,EAAI,EAAGA,EAAID,EAAGC,IACnBN,EAAEiB,QAASf,EAAGb,EAAOU,EAAGO,KACxBJ,GAAK,EASN,OANAP,EAAO,EACFF,EAAE+B,QACN7B,GAAUF,EAAE+B,MAAmB,SAAA,EAAI,GAEpCxB,EAAEyB,SAAUvB,EAAGP,EAAMwB,GAEdnB,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 0b66a04..4b0d1cb 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/array-dataview": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-has-bigint-support": "^0.2.2", - "@stdlib/assert-is-little-endian": "^0.2.2", - "@stdlib/bigint-ctor": "^0.2.2", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^0.2.2", - "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-dataview": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/number-float64-base-from-int64-bytes": "^0.2.2", - "proxyquire": "^2.0.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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b99bdf3 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From bdc84b1e11b26ce0cf853930e0f86b54e9450396 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:24:40 +0000 Subject: [PATCH 104/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 82db5d1..0b66a04 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^0.2.2", "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.1" + "@stdlib/types": "^0.4.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From f31157ac63a666713758781906db9c09fc0d0cd8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:31:39 +0000 Subject: [PATCH 105/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4949 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 d5c20b2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2b6cb64..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b99bdf3..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 62bdcced4afd38d64af9aa263484a72b8263d59e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:32:20 +0000 Subject: [PATCH 106/124] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 223 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 -- test/test.polyfill.js | 299 -- 45 files changed, 4870 insertions(+), 5143 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6ca805a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -235,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -298,7 +289,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ee81373..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 31f573a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte). - - dt: data type (2 bytes). - - ndims: number of dimensions (8 bytes). - - shape: shape (ndims*8 bytes). - - strides: strides in units of bytes (ndims*8 bytes). - - offset: index offset in units of bytes (8 bytes). - - ord: array order (1 byte). - - mode: index mode (1 byte). - - nsubmodes: number of subscript index modes (8 bytes). - - submodes: subscript index modes (nsubmodes*1 bytes). - - flags: flags (4 bytes). - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d68e118..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f4b475b..d5c20b2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2b6cb64 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":";;8/CAuCA,IAAIA,EAASC,IACTC,EAASC,IACTC,EAAQC,ICDZ,IAAIL,EAASC,IACTC,EAASC,IACTC,EAAQC,ICYZ,IAAAC,EATKC,IFmFL,SAAoBC,GACnB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKb,EAAEc,wBACN,OAAOd,EAAEc,0BAqCV,IAlCAX,EAAKY,EAAUf,GACfI,EAAKY,EAAUhB,GAAG,GAClBK,EAAKY,EAAYjB,GAAG,GACpBW,EAAIP,EAAGc,OAGPV,EAAIR,EAAEmB,MAAQ,QAEdP,GADAN,EAAKN,EAAEoB,SAAW,CAAEZ,IACbU,OAGPjB,EAASoB,EAAiBlB,GAS1BM,EAAI,GAHJF,EAAI,IAAIe,EAAU,IAAIC,EAHhB,GAAQ,GAAFZ,EAAQC,KAOlBY,QAASf,EAAG,EAAuB,EAAI,GAGzCA,GAAK,EACLF,EAAEkB,SAAUhB,EAAGjB,EAAQW,GAAMuB,GAG7BjB,GAAK,EACLF,EAAEoB,YAAalB,EAAGmB,EAAQjB,GAAKe,GAG/BhB,EAAQ,EAAJC,EACJF,GAAK,EACCI,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAEoB,YAAalB,EAAGmB,EAAQxB,EAAGS,IAAMa,GACnCnB,EAAEoB,YAAalB,EAAEC,EAAGkB,EAAQvB,EAAGQ,GAAGZ,GAAUyB,GAC5CjB,GAAK,EAoBN,IAjBAA,GAAKC,EACLH,EAAEoB,YAAalB,EAAGmB,EAAQC,EAAW7B,GAAIC,GAAUyB,GAGnDjB,GAAK,EACLF,EAAEiB,QAASf,EAAGf,EAAQoC,EAAU9B,KAGhCS,GAAK,EACLF,EAAEiB,QAASf,EAAGb,EAAOY,IAGrBC,GAAK,EACLF,EAAEoB,YAAalB,EAAGmB,EAAQhB,GAAKc,GAG/BjB,GAAK,EACCI,EAAI,EAAGA,EAAID,EAAGC,IACnBN,EAAEiB,QAASf,EAAGb,EAAOU,EAAGO,KACxBJ,GAAK,EASN,OANAP,EAAO,EACFF,EAAE+B,QACN7B,GAAUF,EAAE+B,MAAmB,SAAA,EAAI,GAEpCxB,EAAEyB,SAAUvB,EAAGP,EAAMwB,GAEdnB,CACR,ECxFA,SAAoBP,GACnB,IAAIC,EACAgC,EACA/B,EAEAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKb,EAAEc,wBACN,OAAOd,EAAEc,0BAsCV,IAnCAX,EAAKY,EAAUf,GACfI,EAAKY,EAAUhB,GAAG,GAClBK,EAAKY,EAAYjB,GAAG,GACpBW,EAAIP,EAAGc,OAGPV,EAAIR,EAAEmB,MAAQ,QAEdP,GADAN,EAAKN,EAAEoB,SAAW,CAAEZ,IACbU,OAGPjB,EAASoB,EAAiBlB,GAM1BI,EAAI,IAAIe,EAAU,IAAIC,EAHhB,GAAQ,GAAFZ,EAAQC,IAIpBqB,EAAQ,IAAIC,EAAY3B,EAAE4B,QAG1B1B,EAAI,EACJF,EAAEiB,QAASf,EAAG,EAAuB,EAAI,GAGzCA,GAAK,EACLF,EAAEkB,SAAUhB,EAAGjB,EAAQW,GAAMuB,GAI7BU,EAAqBzB,EAAGsB,EAAO,EAD/BxB,GAAK,GAILC,EAAQ,EAAJC,EACJF,GAAK,EACCI,EAAI,EAAGA,EAAIF,EAAGE,IACnBuB,EAAqBhC,EAAGS,GAAIoB,EAAO,EAAGxB,GACtC2B,EAAqB/B,EAAGQ,GAAGZ,EAAQgC,EAAO,EAAGxB,EAAEC,GAC/CD,GAAK,EAoBN,IAjBAA,GAAKC,EACL0B,EAAqBP,EAAW7B,GAAIC,EAAQgC,EAAO,EAAGxB,GAGtDA,GAAK,EACLF,EAAEiB,QAASf,EAAGf,EAAQoC,EAAU9B,KAGhCS,GAAK,EACLF,EAAEiB,QAASf,EAAGb,EAAOY,IAIrB4B,EAAqBxB,EAAGqB,EAAO,EAD/BxB,GAAK,GAILA,GAAK,EACCI,EAAI,EAAGA,EAAID,EAAGC,IACnBN,EAAEiB,QAASf,EAAGb,EAAOU,EAAGO,KACxBJ,GAAK,EASN,OANAP,EAAO,EACFF,EAAE+B,QACN7B,GAAUF,EAAE+B,MAAmB,SAAA,EAAI,GAEpCxB,EAAEyB,SAAUvB,EAAGP,EAAMwB,GAEdnB,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 0b66a04..4b0d1cb 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/array-dataview": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-has-bigint-support": "^0.2.2", - "@stdlib/assert-is-little-endian": "^0.2.2", - "@stdlib/bigint-ctor": "^0.2.2", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^0.2.2", - "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-dataview": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/number-float64-base-from-int64-bytes": "^0.2.2", - "proxyquire": "^2.0.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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b99bdf3 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 4bcaca3da2ac98651bea7b611694944a281e64ca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 08:30:41 +0000 Subject: [PATCH 107/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 82db5d1..0b66a04 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^0.2.2", "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.1" + "@stdlib/types": "^0.4.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 61c2ac6e68815d3c05a0a814ce9a57fd80c01e8e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:08:11 +0000 Subject: [PATCH 108/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4949 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 d5c20b2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2b6cb64..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b99bdf3..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 921112ca2d85d1a8d089ea401c2a51d9de8f8f5e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:08:36 +0000 Subject: [PATCH 109/124] 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 | 223 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 -- test/test.polyfill.js | 299 -- 46 files changed, 4870 insertions(+), 5144 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 4d4e2bd..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T06:23:53.855Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6ca805a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -235,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -298,7 +289,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ee81373..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 31f573a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte). - - dt: data type (2 bytes). - - ndims: number of dimensions (8 bytes). - - shape: shape (ndims*8 bytes). - - strides: strides in units of bytes (ndims*8 bytes). - - offset: index offset in units of bytes (8 bytes). - - ord: array order (1 byte). - - mode: index mode (1 byte). - - nsubmodes: number of subscript index modes (8 bytes). - - submodes: subscript index modes (nsubmodes*1 bytes). - - flags: flags (4 bytes). - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d68e118..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f4b475b..d5c20b2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2b6cb64 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 0b66a04..4b0d1cb 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/array-dataview": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-has-bigint-support": "^0.2.2", - "@stdlib/assert-is-little-endian": "^0.2.2", - "@stdlib/bigint-ctor": "^0.2.2", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^0.2.2", - "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-dataview": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/number-float64-base-from-int64-bytes": "^0.2.2", - "proxyquire": "^2.0.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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b99bdf3 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 50e4f8d108bb782c6c81e5702a8875a8db536e6a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 08:18:39 +0000 Subject: [PATCH 110/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 82db5d1..0b66a04 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^0.2.2", "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.1" + "@stdlib/types": "^0.4.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 820481fed7dafa384c7bab0a7fff6b40b86e51a9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:14:48 +0000 Subject: [PATCH 111/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4949 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 d5c20b2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2b6cb64..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b99bdf3..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 39e2ba1e6b236863cc9d6f9a1b1befa2260bdb20 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:15:13 +0000 Subject: [PATCH 112/124] 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 | 223 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 -- test/test.polyfill.js | 299 -- 46 files changed, 4870 insertions(+), 5144 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 aad3727..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T06:26:59.596Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6ca805a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -235,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -298,7 +289,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ee81373..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 31f573a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte). - - dt: data type (2 bytes). - - ndims: number of dimensions (8 bytes). - - shape: shape (ndims*8 bytes). - - strides: strides in units of bytes (ndims*8 bytes). - - offset: index offset in units of bytes (8 bytes). - - ord: array order (1 byte). - - mode: index mode (1 byte). - - nsubmodes: number of subscript index modes (8 bytes). - - submodes: subscript index modes (nsubmodes*1 bytes). - - flags: flags (4 bytes). - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d68e118..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f4b475b..d5c20b2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2b6cb64 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index 0b66a04..4b0d1cb 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/array-dataview": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-has-bigint-support": "^0.2.2", - "@stdlib/assert-is-little-endian": "^0.2.2", - "@stdlib/bigint-ctor": "^0.2.2", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^0.2.2", - "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-dataview": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/number-float64-base-from-int64-bytes": "^0.2.2", - "proxyquire": "^2.0.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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b99bdf3 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 9c52b0f19564a2d3ee7d70148dedf4c473b35f5f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 08:34:12 +0000 Subject: [PATCH 113/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 84b9433..c6ad79b 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^0.2.2", "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.3" + "@stdlib/types": "^0.4.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 48aca16da5c8399eaa9abeea16b20230be8e60c1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 12:38:57 +0000 Subject: [PATCH 114/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4949 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 d5c20b2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2b6cb64..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b99bdf3..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 689232f3ae9d2fb9a19eff3035a5cff9778e941c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 12:39:28 +0000 Subject: [PATCH 115/124] 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 | 223 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 -- test/test.polyfill.js | 299 -- 47 files changed, 4870 insertions(+), 5249 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 da9a77a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T06:36:30.286Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6ca805a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -235,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -298,7 +289,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ee81373..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 31f573a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte). - - dt: data type (2 bytes). - - ndims: number of dimensions (8 bytes). - - shape: shape (ndims*8 bytes). - - strides: strides in units of bytes (ndims*8 bytes). - - offset: index offset in units of bytes (8 bytes). - - ord: array order (1 byte). - - mode: index mode (1 byte). - - nsubmodes: number of subscript index modes (8 bytes). - - submodes: subscript index modes (nsubmodes*1 bytes). - - flags: flags (4 bytes). - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d68e118..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f4b475b..d5c20b2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2b6cb64 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":";;8/CAuCA,IAAIA,EAASC,IACTC,EAASC,IACTC,EAAQC,ICDZ,IAAIL,EAASC,IACTC,EAASC,IACTC,EAAQC,ICYZ,IAAAC,EATKC,IFmFL,SAAoBC,GACnB,IAAIC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKb,EAAEc,wBACN,OAAOd,EAAEc,0BAqCV,IAlCAX,EAAKY,EAAUf,GACfI,EAAKY,EAAUhB,GAAG,GAClBK,EAAKY,EAAYjB,GAAG,GACpBW,EAAIP,EAAGc,OAGPV,EAAIR,EAAEmB,MAAQ,QAEdP,GADAN,EAAKN,EAAEoB,SAAW,CAAEZ,IACbU,OAGPjB,EAASoB,EAAiBlB,GAS1BM,EAAI,GAHJF,EAAI,IAAIe,EAAU,IAAIC,EAHhB,GAAQ,GAAFZ,EAAQC,KAOlBY,QAASf,EAAG,EAAuB,EAAI,GAGzCA,GAAK,EACLF,EAAEkB,SAAUhB,EAAGjB,EAAQW,GAAMuB,GAG7BjB,GAAK,EACLF,EAAEoB,YAAalB,EAAGmB,EAAQjB,GAAKe,GAG/BhB,EAAQ,EAAJC,EACJF,GAAK,EACCI,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAEoB,YAAalB,EAAGmB,EAAQxB,EAAGS,IAAMa,GACnCnB,EAAEoB,YAAalB,EAAEC,EAAGkB,EAAQvB,EAAGQ,GAAGZ,GAAUyB,GAC5CjB,GAAK,EAoBN,IAjBAA,GAAKC,EACLH,EAAEoB,YAAalB,EAAGmB,EAAQC,EAAW7B,GAAIC,GAAUyB,GAGnDjB,GAAK,EACLF,EAAEiB,QAASf,EAAGf,EAAQoC,EAAU9B,KAGhCS,GAAK,EACLF,EAAEiB,QAASf,EAAGb,EAAOY,IAGrBC,GAAK,EACLF,EAAEoB,YAAalB,EAAGmB,EAAQhB,GAAKc,GAG/BjB,GAAK,EACCI,EAAI,EAAGA,EAAID,EAAGC,IACnBN,EAAEiB,QAASf,EAAGb,EAAOU,EAAGO,KACxBJ,GAAK,EASN,OANAP,EAAO,EACFF,EAAE+B,QACN7B,GAAUF,EAAE+B,MAAmB,SAAA,EAAI,GAEpCxB,EAAEyB,SAAUvB,EAAGP,EAAMwB,GAEdnB,CACR,ECxFA,SAAoBP,GACnB,IAAIC,EACAgC,EACA/B,EAEAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKb,EAAEc,wBACN,OAAOd,EAAEc,0BAsCV,IAnCAX,EAAKY,EAAUf,GACfI,EAAKY,EAAUhB,GAAG,GAClBK,EAAKY,EAAYjB,GAAG,GACpBW,EAAIP,EAAGc,OAGPV,EAAIR,EAAEmB,MAAQ,QAEdP,GADAN,EAAKN,EAAEoB,SAAW,CAAEZ,IACbU,OAGPjB,EAASoB,EAAiBlB,GAM1BI,EAAI,IAAIe,EAAU,IAAIC,EAHhB,GAAQ,GAAFZ,EAAQC,IAIpBqB,EAAQ,IAAIC,EAAY3B,EAAE4B,QAG1B1B,EAAI,EACJF,EAAEiB,QAASf,EAAG,EAAuB,EAAI,GAGzCA,GAAK,EACLF,EAAEkB,SAAUhB,EAAGjB,EAAQW,GAAMuB,GAI7BU,EAAqBzB,EAAGsB,EAAO,EAD/BxB,GAAK,GAILC,EAAQ,EAAJC,EACJF,GAAK,EACCI,EAAI,EAAGA,EAAIF,EAAGE,IACnBuB,EAAqBhC,EAAGS,GAAIoB,EAAO,EAAGxB,GACtC2B,EAAqB/B,EAAGQ,GAAGZ,EAAQgC,EAAO,EAAGxB,EAAEC,GAC/CD,GAAK,EAoBN,IAjBAA,GAAKC,EACL0B,EAAqBP,EAAW7B,GAAIC,EAAQgC,EAAO,EAAGxB,GAGtDA,GAAK,EACLF,EAAEiB,QAASf,EAAGf,EAAQoC,EAAU9B,KAGhCS,GAAK,EACLF,EAAEiB,QAASf,EAAGb,EAAOY,IAIrB4B,EAAqBxB,EAAGqB,EAAO,EAD/BxB,GAAK,GAILA,GAAK,EACCI,EAAI,EAAGA,EAAID,EAAGC,IACnBN,EAAEiB,QAASf,EAAGb,EAAOU,EAAGO,KACxBJ,GAAK,EASN,OANAP,EAAO,EACFF,EAAE+B,QACN7B,GAAUF,EAAE+B,MAAmB,SAAA,EAAI,GAEpCxB,EAAEyB,SAAUvB,EAAGP,EAAMwB,GAEdnB,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index c6ad79b..4b0d1cb 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/array-dataview": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-has-bigint-support": "^0.2.2", - "@stdlib/assert-is-little-endian": "^0.2.2", - "@stdlib/bigint-ctor": "^0.2.2", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^0.2.2", - "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-dataview": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/number-float64-base-from-int64-bytes": "^0.2.2", - "proxyquire": "^2.0.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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b99bdf3 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From fd9ac1190c0ce28490c0f686bcaf0076661a67f1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Dec 2024 01:46:48 +0000 Subject: [PATCH 116/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 84b9433..c6ad79b 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^0.2.2", "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.3" + "@stdlib/types": "^0.4.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From fdd94a1e8f48ffd1dcfe9c0a81d534d1efbd7fec Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Dec 2024 01:48:08 +0000 Subject: [PATCH 117/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4949 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 d5c20b2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2b6cb64..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b99bdf3..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 22c0f5ba07a6a830cee9947e569a00ec75dfd506 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Dec 2024 01:48:32 +0000 Subject: [PATCH 118/124] 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 | 223 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 -- test/test.polyfill.js | 299 -- 47 files changed, 4870 insertions(+), 5249 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 f9ee6fe..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-09T01:46:17.343Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6ca805a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -235,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -298,7 +289,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ee81373..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAc,QAAS,sBAAuB,EAC9CC,EAAW,QAAS,wBAAyB,EAC7CC,EAAS,QAAS,qBAAsB,EACxCC,EAAkB,QAAS,wCAAyC,EACpEC,EAAS,QAAS,wBAAyB,EAAE,KAC7CC,EAAS,QAAS,wBAAyB,EAAE,KAC7CC,EAAQ,QAAS,6BAA8B,EAAE,KACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EAKjDC,EAASR,EAAO,EAChBS,EAASR,EAAO,EAChBS,EAAQR,EAAM,EAuFlB,SAASS,EAAWC,EAAI,CACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKd,EAAE,wBACN,OAAOA,EAAE,wBAAwB,EAqClC,IAlCAI,EAAKb,EAAUS,CAAE,EACjBK,EAAKb,EAAUQ,EAAG,EAAM,EACxBM,EAAKb,EAAYO,EAAG,EAAM,EAC1BY,EAAIP,EAAG,OAGPI,EAAIT,EAAE,MAAQ,QACdO,EAAKP,EAAE,SAAW,CAAES,CAAE,EACtBI,EAAIN,EAAG,OAGPN,EAASd,EAAiBiB,CAAG,EAG7BD,EAAM,GAAMS,EAAE,GAAMC,EAGpBL,EAAI,IAAIvB,EAAU,IAAID,EAAamB,CAAI,CAAE,EAGzCO,EAAI,EACJF,EAAE,QAASE,EAAK3B,EAAqB,EAAI,CAAE,EAG3C2B,GAAK,EACLF,EAAE,SAAUE,EAAGd,EAAQQ,CAAG,EAAGrB,CAAiB,EAG9C2B,GAAK,EACLF,EAAE,YAAaE,EAAGxB,EAAQ0B,CAAE,EAAG7B,CAAiB,EAGhD4B,EAAIC,EAAI,EACRF,GAAK,EACCI,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAE,YAAaE,EAAGxB,EAAQmB,EAAGS,CAAC,CAAE,EAAG/B,CAAiB,EACpDyB,EAAE,YAAaE,EAAEC,EAAGzB,EAAQoB,EAAGQ,CAAC,EAAEb,CAAO,EAAGlB,CAAiB,EAC7D2B,GAAK,EAoBN,IAjBAA,GAAKC,EACLH,EAAE,YAAaE,EAAGxB,EAAQQ,EAAWM,CAAE,EAAEC,CAAO,EAAGlB,CAAiB,EAGpE2B,GAAK,EACLF,EAAE,QAASE,EAAGb,EAAQF,EAAUK,CAAE,CAAE,CAAE,EAGtCU,GAAK,EACLF,EAAE,QAASE,EAAGZ,EAAOW,CAAE,CAAE,EAGzBC,GAAK,EACLF,EAAE,YAAaE,EAAGxB,EAAQ2B,CAAE,EAAG9B,CAAiB,EAGhD2B,GAAK,EACCI,EAAI,EAAGA,EAAID,EAAGC,IACnBN,EAAE,QAASE,EAAGZ,EAAOS,EAAGO,CAAC,CAAE,CAAE,EAC7BJ,GAAK,EAGN,OAAAR,EAAO,EACFF,EAAE,QACNE,GAAUF,EAAE,MAAM,SAAa,EAAI,GAEpCQ,EAAE,SAAUE,EAAGR,EAAMnB,CAAiB,EAE/ByB,CACR,CAKA1B,EAAO,QAAUiB,IC/NjB,IAAAgB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAsB,QAAS,4CAA6C,EAAE,OAC9EC,EAAc,QAAS,sBAAuB,EAC9CC,EAAa,QAAS,qBAAsB,EAC5CC,EAAW,QAAS,wBAAyB,EAC7CC,EAAkB,QAAS,wCAAyC,EACpEC,EAAS,QAAS,wBAAyB,EAAE,KAC7CC,EAAS,QAAS,wBAAyB,EAAE,KAC7CC,EAAQ,QAAS,6BAA8B,EAAE,KACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EAKjDC,GAASR,EAAO,EAChBS,GAASR,EAAO,EAChBS,EAAQR,EAAM,EAwFlB,SAASS,GAAWC,EAAI,CACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GAAKf,EAAE,wBACN,OAAOA,EAAE,wBAAwB,EAsClC,IAnCAK,EAAKd,EAAUS,CAAC,EAChBM,EAAKd,EAAUQ,EAAG,EAAM,EACxBO,EAAKd,EAAYO,EAAG,EAAM,EAC1Ba,EAAIP,EAAG,OAGPI,EAAIV,EAAE,MAAQ,QACdQ,EAAKR,EAAE,SAAW,CAAEU,CAAE,EACtBI,EAAIN,EAAG,OAGPP,EAASd,EAAiBkB,CAAG,EAG7BD,EAAM,GAAMS,EAAE,GAAMC,EAGpBL,EAAI,IAAIvB,EAAU,IAAIF,EAAaoB,CAAI,CAAE,EACzCF,EAAQ,IAAIjB,EAAYwB,EAAE,MAAO,EAGjCE,EAAI,EACJF,EAAE,QAASE,EAAK7B,EAAqB,EAAI,CAAE,EAG3C6B,GAAK,EACLF,EAAE,SAAUE,EAAGf,GAAQS,CAAG,EAAGvB,CAAiB,EAG9C6B,GAAK,EACL5B,EAAqB8B,EAAGX,EAAO,EAAGS,CAAE,EAGpCC,EAAIC,EAAI,EACRF,GAAK,EACCI,EAAI,EAAGA,EAAIF,EAAGE,IACnBhC,EAAqBuB,EAAGS,CAAC,EAAGb,EAAO,EAAGS,CAAE,EACxC5B,EAAqBwB,EAAGQ,CAAC,EAAEd,EAAQC,EAAO,EAAGS,EAAEC,CAAE,EACjDD,GAAK,EAoBN,IAjBAA,GAAKC,EACL7B,EAAqBW,EAAWM,CAAE,EAAEC,EAAQC,EAAO,EAAGS,CAAE,EAGxDA,GAAK,EACLF,EAAE,QAASE,EAAGd,GAAQF,EAAUK,CAAE,CAAE,CAAE,EAGtCW,GAAK,EACLF,EAAE,QAASE,EAAGb,EAAOY,CAAE,CAAE,EAGzBC,GAAK,EACL5B,EAAqB+B,EAAGZ,EAAO,EAAGS,CAAE,EAGpCA,GAAK,EACCI,EAAI,EAAGA,EAAID,EAAGC,IACnBN,EAAE,QAASE,EAAGb,EAAOU,EAAGO,CAAC,CAAE,CAAE,EAC7BJ,GAAK,EAGN,OAAAR,EAAO,EACFH,EAAE,QACNG,GAAUH,EAAE,MAAM,SAAa,EAAI,GAEpCS,EAAE,SAAUE,EAAGR,EAAMrB,CAAiB,EAE/B2B,CACR,CAKA5B,EAAO,QAAUkB,KC9LjB,IAAIiB,GAAmB,QAAS,mCAAoC,EAChEC,GAAU,IACVC,GAAW,IAKXC,EACCH,GAAiB,EACrBG,EAAOF,GAEPE,EAAOD,GAMR,OAAO,QAAUC", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 31f573a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte). - - dt: data type (2 bytes). - - ndims: number of dimensions (8 bytes). - - shape: shape (ndims*8 bytes). - - strides: strides in units of bytes (ndims*8 bytes). - - offset: index offset in units of bytes (8 bytes). - - ord: array order (1 byte). - - mode: index mode (1 byte). - - nsubmodes: number of subscript index modes (8 bytes). - - submodes: subscript index modes (nsubmodes*1 bytes). - - flags: flags (4 bytes). - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d68e118..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f4b475b..d5c20b2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2b6cb64 --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index c6ad79b..4b0d1cb 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/array-dataview": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-has-bigint-support": "^0.2.2", - "@stdlib/assert-is-little-endian": "^0.2.2", - "@stdlib/bigint-ctor": "^0.2.2", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^0.2.2", - "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-dataview": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/number-float64-base-from-int64-bytes": "^0.2.2", - "proxyquire": "^2.0.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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b99bdf3 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 35424f7bb340ed00d6320d661407e013f1bd7934 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 13 Jan 2025 02:21:06 +0000 Subject: [PATCH 119/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 84b9433..c6ad79b 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^0.2.2", "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.3" + "@stdlib/types": "^0.4.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 6d0eebe2d5668095cfd4d7ad3d919f5d6dad0c84 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 13 Jan 2025 02:53:40 +0000 Subject: [PATCH 120/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4949 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 d5c20b2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2b6cb64..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b99bdf3..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d9363b1fa4961d349168e9280a6cdb612e832159 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 13 Jan 2025 02:54:18 +0000 Subject: [PATCH 121/124] 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 | 223 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 -- test/test.polyfill.js | 299 -- 47 files changed, 4870 insertions(+), 5249 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index acdab6e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-01-13T02:09:40.254Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6ca805a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -235,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -298,7 +289,7 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ee81373..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 31f573a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte). - - dt: data type (2 bytes). - - ndims: number of dimensions (8 bytes). - - shape: shape (ndims*8 bytes). - - strides: strides in units of bytes (ndims*8 bytes). - - offset: index offset in units of bytes (8 bytes). - - ord: array order (1 byte). - - mode: index mode (1 byte). - - nsubmodes: number of subscript index modes (8 bytes). - - submodes: subscript index modes (nsubmodes*1 bytes). - - flags: flags (4 bytes). - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d68e118..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f4b475b..d5c20b2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3dcfdce --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index c6ad79b..4b0d1cb 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/array-dataview": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-has-bigint-support": "^0.2.2", - "@stdlib/assert-is-little-endian": "^0.2.2", - "@stdlib/bigint-ctor": "^0.2.2", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^0.2.2", - "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-dataview": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/number-float64-base-from-int64-bytes": "^0.2.2", - "proxyquire": "^2.0.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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b99bdf3 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); From 5062eada4ae7e0ecee86c800e091d2e8d466f92b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 01:41:24 +0000 Subject: [PATCH 122/124] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 84b9433..c6ad79b 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "@stdlib/ndarray-index-modes": "^0.2.2", "@stdlib/ndarray-orders": "^0.2.2", "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.3" + "@stdlib/types": "^0.4.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -105,4 +106,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 8d6a5588a6c28213a3807f10dfd65d7fbdee2711 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 01:51:51 +0000 Subject: [PATCH 123/124] Remove files --- index.d.ts | 102 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4949 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 d5c20b2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8] -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)` -* -* @param x - input ndarray -* @returns serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -declare function serialize( x: ndarray ): DataView; - - -// EXPORTS // - -export = serialize; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3dcfdce..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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b99bdf3..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From da9ae76e8e35f501cba73ac7ffa2665d7970fab6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 01:52:20 +0000 Subject: [PATCH 124/124] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 223 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 166 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 46 - docs/types/test.ts | 77 - examples/index.js | 74 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 55 - lib/main.js | 224 - lib/polyfill.js | 228 - package.json | 78 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 62 - test/test.main.js | 299 -- test/test.polyfill.js | 299 -- 47 files changed, 4870 insertions(+), 5248 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 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) 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 lib/polyfill.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js delete mode 100644 test/test.polyfill.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 3fe84f7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-01-20T01:37:55.294Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e1cf76a..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 997ea6f..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/serialize-meta-data) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6ca805a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '28 4 * * 1' - - # 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 + + ```
@@ -235,7 +226,7 @@ console.log( 'order (enum): %d', order ); ## 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]. @@ -298,7 +289,7 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-serialize-meta-data/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3883ad9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var pkg = require( './../package.json' ).name; -var serialize = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var opts; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - opts = { - 'readonly': true - }; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order, opts ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = serialize( values[ i%values.length ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isDataView( out ) ) { - b.fail( 'should return a DataView' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index ee81373..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/serialize-meta-data" -%% click B href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/serialize-meta-data -[production-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-serialize-meta-data/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 2de6130..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import serialize from '../docs/types/index'; -export = serialize; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5802999..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var w=function(a,i){return function(){return i||a((i={exports:{}}).exports,i),i.exports}};var h=w(function(nr,p){ -var g=require('@stdlib/assert-is-little-endian/dist'),T=require('@stdlib/array-buffer/dist'),N=require('@stdlib/array-dataview/dist'),d=require('@stdlib/bigint-ctor/dist'),A=require('@stdlib/ndarray-base-bytes-per-element/dist'),L=require('@stdlib/ndarray-dtypes/dist').enum,R=require('@stdlib/ndarray-orders/dist').enum,c=require('@stdlib/ndarray-index-modes/dist').enum,M=require('@stdlib/ndarray-base-dtype/dist'),P=require('@stdlib/ndarray-base-shape/dist'),Y=require('@stdlib/ndarray-base-strides/dist'),z=require('@stdlib/ndarray-base-offset/dist'),V=require('@stdlib/ndarray-base-order/dist'),U=L(),j=R(),S=c();function k(a){var i,n,l,I,_,o,m,t,s,r,e,f,u,v;if(a.__array_meta_dataview__)return a.__array_meta_dataview__();for(I=M(a),_=P(a,!1),o=Y(a,!1),f=_.length,s=a.mode||"throw",m=a.submode||[s],u=m.length,i=A(I),l=33+f*16+u,t=new N(new T(l)),r=0,t.setInt8(r,g?1:0),r+=1,t.setInt16(r,U[I],g),r+=2,t.setBigInt64(r,d(f),g),e=f*8,r+=8,v=0;v (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nmodule.exports = serialize;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar builtin = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_main", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "float64ToInt64Bytes", "ArrayBuffer", "Uint8Array", "DataView", "bytesPerElement", "dtypes", "orders", "modes", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "DTYPES", "ORDERS", "MODES", "serialize", "x", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "hasBigIntSupport", "builtin", "polyfill", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 31f573a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,46 +0,0 @@ - -{{alias}}( x ) - Serializes ndarray meta data. - - Meta data format: - - |endianness|dt|ndims|shape|strides|offset|ord|mode|nsubmodes|submodes|flags| - - where - - - endianness: byte order (1 byte). - - dt: data type (2 bytes). - - ndims: number of dimensions (8 bytes). - - shape: shape (ndims*8 bytes). - - strides: strides in units of bytes (ndims*8 bytes). - - offset: index offset in units of bytes (8 bytes). - - ord: array order (1 byte). - - mode: index mode (1 byte). - - nsubmodes: number of subscript index modes (8 bytes). - - submodes: subscript index modes (nsubmodes*1 bytes). - - flags: flags (4 bytes). - - Serialization is performed according to host byte order (endianness). - - If the endianness is 1, the byte order is little endian. If the endianness - is 0, the byte order is big endian. - - Parameters - ---------- - x: ndarray - Input ndarray. - - Returns - ------- - out: DataView - Meta data serialized as a DataView. - - Examples - -------- - > var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var out = {{alias}}( arr ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d68e118..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import serialize = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a DataView... -{ - const x = array(); - serialize( x ); // $ExpectType DataView -} - -// The compiler throws an error if the function is not provided an ndarray... -{ - serialize( '5' ); // $ExpectError - serialize( 123 ); // $ExpectError - serialize( true ); // $ExpectError - serialize( false ); // $ExpectError - serialize( null ); // $ExpectError - serialize( [] ); // $ExpectError - serialize( {} ); // $ExpectError - serialize( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - serialize(); // $ExpectError - serialize( x, 5 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 466e29a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var array = require( '@stdlib/ndarray-array' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var fromInt64Bytes = require( '@stdlib/number-float64-base-from-int64-bytes' ); -var serialize = require( './../lib' ); - -// Create an ndarray: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Print various properties: -console.log( 'dtype: %s', x.dtype ); -console.log( 'ndims: %d', x.ndims ); -console.log( 'shape: [ %s ]', x.shape.join( ', ' ) ); -console.log( 'strides: [ %s ]', x.strides.join( ', ' ) ); -console.log( 'offset: %d', x.offset ); -console.log( 'order: %s', x.order ); - -// Serialize ndarray meta data to a DataView: -var dv = serialize( x ); -// returns - -// Create a Uint8Array view: -var bytes = new Uint8Array( dv.buffer ); - -// Extract the data type (enum): -var dtype = dv.getInt16( 1, IS_LITTLE_ENDIAN ); -console.log( 'dtype (enum): %d', dtype ); - -// Extract the number of dimensions: -var ndims = fromInt64Bytes( bytes, 1, 3 ); -console.log( 'ndims: %d', ndims ); - -// Extract the shape: -var shape = []; -var i; -for ( i = 0; i < ndims; i++ ) { - shape.push( fromInt64Bytes( bytes, 1, 11+(i*8) ) ); -} -console.log( 'shape: [ %s ]', shape.join( ', ' ) ); - -// Extract the strides (in units of bytes): -var strides = []; -for ( i = 0; i < ndims; i++ ) { - strides.push( fromInt64Bytes( bytes, 1, 11+(ndims*8)+(i*8) ) ); -} -console.log( 'strides (bytes): [ %s ]', strides.join( ', ' ) ); - -// Extract the index offset (in bytes): -var offset = fromInt64Bytes( bytes, 1, 11+(ndims*16) ); -console.log( 'offset (bytes): %d', offset ); - -// Extract the order (enum): -var order = dv.getInt8( 19+(ndims*16) ); -console.log( 'order (enum): %d', order ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f4b475b..d5c20b2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3dcfdce --- /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 t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import{enum as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";var b=i(),g=m(),_=a();var y=i(),c=m(),x=a();var u=t()?function(t){var i,m,a,p,f,y,c,x,u,I,w,B,A;if(t.__array_meta_dataview__)return t.__array_meta_dataview__();for(a=o(t),p=j(t,!1),f=l(t,!1),w=p.length,x=t.mode||"throw",B=(y=t.submode||[x]).length,i=d(a),u=0,(c=new r(new e(33+16*w+B))).setInt8(u,s?1:0),u+=1,c.setInt16(u,b[a],s),u+=2,c.setBigInt64(u,n(w),s),I=8*w,u+=8,A=0;A (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x );\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport Uint8Array from '@stdlib/array-uint8';\nimport DataView from '@stdlib/array-dataview';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport getDType from '@stdlib/ndarray-base-dtype';\nimport getShape from '@stdlib/ndarray-base-shape';\nimport getStrides from '@stdlib/ndarray-base-strides';\nimport getOffset from '@stdlib/ndarray-base-offset';\nimport getOrder from '@stdlib/ndarray-base-order';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// MAIN //\n\n/**\n* Serializes ndarray meta data.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @param {ndarrayLike} x - input array\n* @param {string} x.dtype - array data type\n* @param {NonNegativeIntegerArray} x.shape - array shape\n* @param {IntegerArray} x.strides - array strides\n* @param {NonNegativeInteger} x.offset - array index offset\n* @param {string} x.order - array order\n* @param {string} [x.mode='throw'] - array index mode\n* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes\n* @param {Object} [x.flags={}] - array flags\n* @returns {DataView} serialized meta data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\nfunction serialize( x ) {\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\t// Check for interface which does the work of serializing to a DataView for us...\n\tif ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle\n\t\treturn x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle\n\t}\n\t// Extract meta data known to be attached to ndarray-like objects:\n\tdt = getDType( x);\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length; // ndims\n\n\t// Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances):\n\tm = x.mode || 'throw';\n\tsm = x.submode || [ m ];\n\tM = sm.length;\n\n\t// Determine number of bytes per element according to the ndarray dtype:\n\tnbytes = bytesPerElement( dt );\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ getOrder( x ) ] );\n\n\t// Index mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tif ( x.flags ) {\n\t\tflgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\t}\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\treturn v;\n}\n\n\n// EXPORTS //\n\nexport default serialize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serialize ndarray meta data.\n*\n* @module @stdlib/ndarray-base-serialize-meta-data\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n* import serialize from '@stdlib/ndarray-base-serialize-meta-data';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n*\n* var dv = serialize( x );\n* // returns \n*/\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport builtin from './main.js';\nimport polyfill from './polyfill.js';\n\n\n// MAIN //\n\nvar main;\nif ( hasBigIntSupport() ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DTYPES","dtypes","ORDERS","orders","MODES","modes","main$1","hasBigIntSupport","x","nbytes","flgs","dt","sh","st","sm","v","m","o","s","N","M","i","__array_meta_dataview__","getDType","getShape","getStrides","length","mode","submode","bytesPerElement","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","getOffset","getOrder","flags","setInt32","bytes","Uint8Array","buffer","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1609eb0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Serialize ndarray meta data. -* -* @module @stdlib/ndarray-base-serialize-meta-data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var serialize = require( '@stdlib/ndarray-base-serialize-meta-data' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var main; -if ( hasBigIntSupport() ) { - main = builtin; -} else { - main = polyfill; -} - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 731b1e8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x ); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( getOffset( x )*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/lib/polyfill.js b/lib/polyfill.js deleted file mode 100644 index ad72893..0000000 --- a/lib/polyfill.js +++ /dev/null @@ -1,228 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var DataView = require( '@stdlib/array-dataview' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// MAIN // - -/** -* Serializes ndarray meta data. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @param {ndarrayLike} x - input array -* @param {string} x.dtype - array data type -* @param {NonNegativeIntegerArray} x.shape - array shape -* @param {IntegerArray} x.strides - array strides -* @param {NonNegativeInteger} x.offset - array index offset -* @param {string} x.order - array order -* @param {string} [x.mode='throw'] - array index mode -* @param {StringArray} [x.submode=[x.mode]] - array subscript index modes -* @param {Object} [x.flags={}] - array flags -* @returns {DataView} serialized meta data -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* -* var dv = serialize( x ); -* // returns -*/ -function serialize( x ) { - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - // Check for interface which does the work of serializing to a DataView for us... - if ( x.__array_meta_dataview__ ) { // eslint-disable-line no-underscore-dangle - return x.__array_meta_dataview__(); // eslint-disable-line no-underscore-dangle - } - // Extract meta data known to be attached to ndarray-like objects: - dt = getDType( x); - sh = getShape( x, false ); - st = getStrides( x, false ); - N = sh.length; // ndims - - // Extract meta data which may be available on ndarray-like objects (e.g., stdlib ndarray instances): - m = x.mode || 'throw'; - sm = x.submode || [ m ]; - M = sm.length; - - // Determine number of bytes per element according to the ndarray dtype: - nbytes = bytesPerElement( dt ); - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( getOffset( x )*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ getOrder( x ) ] ); - - // Index mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of index submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - if ( x.flags ) { - flgs |= ( x.flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - } - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - return v; -} - - -// EXPORTS // - -module.exports = serialize; diff --git a/package.json b/package.json index c6ad79b..4b0d1cb 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Serialize ndarray meta data.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/array-dataview": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-has-bigint-support": "^0.2.2", - "@stdlib/assert-is-little-endian": "^0.2.2", - "@stdlib/bigint-ctor": "^0.2.2", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^0.2.2", - "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-dataview": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/number-float64-base-from-int64-bytes": "^0.2.2", - "proxyquire": "^2.0.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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,9 +30,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b99bdf3 --- /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 1c0b843..0000000 --- a/test/test.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var main = require( './../lib/main.js' ); -var polyfill = require( './../lib/polyfill.js' ); -var serialize = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment support BigInts, the function includes BigInt operations', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, main, 'is expected value' ); - t.end(); - - function hasSupport() { - return true; - } -}); - -tape( 'if an environment does not support BigInts, the function is a polyfill', function test( t ) { - var serialize = proxyquire( './../lib', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - t.strictEqual( serialize, polyfill, 'is expected value' ); - t.end(); - - function hasSupport() { - return false; - } -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8164681..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/main.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); diff --git a/test/test.polyfill.js b/test/test.polyfill.js deleted file mode 100644 index aebe5bc..0000000 --- a/test/test.polyfill.js +++ /dev/null @@ -1,299 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var serialize = require( './../lib/polyfill.js' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof serialize, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'flags': { - 'READONLY': true - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 4 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); -}); - -tape( 'the function serializes ndarray meta data to a DataView (ndarray-like object; modes)', function test( t ) { - var expected; - var strides; - var nbytes; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'order': order, - 'offset': offset, - 'mode': 'wrap', - 'submode': [ 'clamp', 'wrap', 'throw', 'normalize' ], - 'flags': { - 'READONLY': false - } - }; - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'wrap' ], - 'nsubmodes': 4, - 'submodes': [ MODES[ 'clamp' ], MODES[ 'wrap' ], MODES[ 'throw' ], MODES[ 'normalize' ] ], - 'flags': 0 - }; - - actual = serialize( arr ); - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(4*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - nbytes = bytesPerElement( dtype ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*nbytes, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*nbytes, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*nbytes, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.submodes[ 1 ], 'returns expected submode' ); - t.strictEqual( bytes[ 63 ], expected.submodes[ 2 ], 'returns expected submode' ); - t.strictEqual( bytes[ 64 ], expected.submodes[ 3 ], 'returns expected submode' ); - t.strictEqual( bytes[ 68 ], expected.flags, 'returns expected flags' ); - } - t.end(); -});